Stefan Krah added the comment: Oscar Benjamin <rep...@bugs.python.org> wrote: > If you're going to use decimals though then you can trap inexact and > keep increasing the precision until it becomes exact.
For sums that is not necessary. Create a context with MAX_EMAX, MIN_EMIN and MAX_PREC and mpd_add() -- the underlying libmpdec function -- will only use as many digits as neccessary. Of course, calculating 1/3 in MAX_PREC would be catastrophic. > The problem is with rationals that cannot be expressed in a finite number > of decimal > digits - these need to be handled separately. I've attached > decimalsum.py that shows how to compute an exact sum of any mix of > int, float and Decimal, but not Fraction. Yes, I was thinking of a "don't do that" approach. Do people have mixed Fractions and Decimals in their data? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20499> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com