Although not exactly an answer to your question, I think we should mention here Rational class, suitable for keeping rational numbers without the loss implied with storage of float-point numbers, i.e. in form of fractions: