Rational. An arbitrary precision rational number
We use computers for doing floating point calculations. However even using 64 bit types, lack of precision in calculations produce inaccuracies that go accumulating over time, thus increasing the error.
For example, lets compute y = 2/1 * 3/2 * 4/3 * ... If done n times, result has to be n.
However, the code implementing this will fail:
double val = 1;
for (double d = 1; d < 100; ++d)
val *= (d+1)/d;
Cout() << "double == 100: " << ((dval == 100) ? "true" : "false") << "\n"; // It returns false!?!?
Rational class solves this drawback implementing an arbitrary precision integer rational number.
