Hey
@ne555 thanks for your reply. Until I am more sure about the usage, I will rename the inverse() function, which actually inverts the Rational to 'invert'. I'll keep in mind removing it, if it deems itself not very useful.
prefer member functions to non-member friends.
(but prefer non-member non-friend to member) |
I am afraid I wasn't quite able to grasp what you mean (my english is kinda rusty, sorry).
I believe it means, that my design choice making to_double a friend function is not optimal?
I was thinking about declaring it like so:
static double to_double(const Rational&)
Would that be the preferred choice? Or did you mean something different? It's just, if I make it non-friend non-member, I will habe to provide facilities to access num and denom. I could just make them public, but I am not sure that is the right way to go.
I added the whole "safe_..." and "..._is_safe", because I want my Rational class to detect overflows (or do I? Think so...). Even if it is something that is unlikely to occur, especially after I changed the double to Rational constructor to use an approximation, I think if it ever happened it shouldn't go unnoticed.
If I understand correctly, are you suggesting I made safe_add, ... private? Would make sense, since they are meant for implementation only. Or, I could leave the regular '+=' "unsafe", making it more efficient, and keep the safe_add public, so one can use it, if they fear of overflows...
exact is quite a big word. |
indeed. I just looked into that, and it turns out something is flawed with my implementation. Feeding 123.123456789 gives a numerator of 123123457, which is not how I imagined it to be, but (123123456789 / 1000000000) which would be rather exact (if I feed it to python it spits out 123.123456789), however I believe maybe the limitation of using integers as numerator and denominator puts an end to that. Or maybe something gets lost somewhere during all those conversions...
I am really considering removing that...
After doing more checks, I believe I must overlook my approximation method, too. It does not work properly for small tolerances.
Anyhow, thank you very much for looking into my code, I really appreciate it.