Comment by dwohnitmok
2 hours ago
This is potentially horrendous for performance, and even worse, unpredictably so. Instead of getting the incorrect answer (or NaN) with floating point if you have an unfortunate series of calculations, you get extreme memory blowup, where your numerator and denominator can explode in size, which in turn leads to runtime slowdown. In the worst case you can actually run out of memory (because certain fairly natural calculations can cause your numerators and denominators to very rapidly explode in size).
Committing to unbounded rationals basically opens your system up to DoS attacks.
You could decide to bound rationals in the numerator and denominator, but then you've more or less reinvented a form of floating point.
In order of preference for a high reliability production system I would use:
1. Integers
2. Fixed point
3. Floating point
4. Rationals [waaaayyyy down in fourth place]
Most systems don't have high enough reliability needs though that I would favor fixed point over floating point and so in practice I rarely use fixed point (simply because library and language support is far worse).
No comments yet
Contribute on Hacker News ↗