Chris Angelico <ros...@gmail.com>: > The trouble is, repeated addition of fractions is *able* to deliver an > exact result. It just might result in an incredibly slow program.
True, although the programmer has control over the feature. If you *want* the luxury of exact fractions, you pay the price. If you don't, you make the numbers inexact. A somewhat analogous situation is there in Python's integers, which have an unlimited range. The feature is extremely useful in cryptography, for example (DSA verification is a couple of lines of Python). > And then if you mix types, does it aim for the greatest possible > 'accuracy', even if that's not quite accurate? (For instance, if you > add 0.2 to 5/8, does it convert to float or to fraction?) Thus inexactness is a contagious property of a number. <URL: http://www.schemers.org/Documents/Standards/R5RS/HTML/r5r s-Z-H-9.html#%_sec_6.2.3> Guile: (+ 0.2 5/8) ==> 0.825 (exact? (+ 0.2 5/8)) ==> #f Python, for comparison: >>> 0.2 + fractions.Fraction(5, 8) 0.825 >>> decimal.Decimal("0.1") + 0.1 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'decimal.Decimal' and 'float' >>> fractions.Fraction(5, 8) + decimal.Decimal("0.1") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'Fraction' and 'decim al.Decimal' Marko -- https://mail.python.org/mailman/listinfo/python-list