Raymond Hettinger <raymond.hettin...@gmail.com> wrote: > > On Mar 22, 2010, at 11:26 AM, Mark Dickinson wrote: > > > > Just for the record, I'd also prefer Decimal + Fraction -> Decimal. > > > Guido was persuasive on why float + Fraction --> float, > so this makes sense for the same reasons. > > For the implementation, is there a way to avoid the double rounding > in myfloat + myfrac.numerator / myfrac.denominator? > > Perhaps translate it to: > > f = Fractions.from_decimal(myfloat) + myfract # Lossless, exact > addition > return f.numerator / f.denominator # Only one decimal context > rounding applied. > > Elsewhere in the decimal module, there is a fundamental notion > that numbers are exact and only the results of operations are > rounded. For example, it is possible in decimal to add together > two high precision numbers but do so in a low precision context.
I don't think this will be practical for huge decimal exponents. Also, at first glance I wonder how to integrate this cleanly into the control flow. convert_other() will not work, so there would need to be a special case for fractions in each function. Or do you mean to outsource the whole computation to the fractions module, which calls decimal only for the final division? Stefan Krah _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com