A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-March/098726.html below:

[Python-Dev] Mixing float and Decimal -- thread reboot

[Python-Dev] Mixing float and Decimal -- thread rebootGreg Ewing greg.ewing at canterbury.ac.nz
Tue Mar 23 00:05:47 CET 2010
Mark Dickinson wrote:

> But the Fraction type is going to mess this up:  for Decimal +
> Fraction ->  Decimal, I don't see any other sensible option than to
> convert the Fraction using the current context, since lossless
> conversion isn't generally possible.

You could convert the Decimal to a Fraction, do the arithmetic
as Fractions, and convert the result back to Decimal using the
current precision.

I think this would satisfy the principle of performing the
calculation as though infinite precision were available, and
the final rounding is justified, since seen from the outside
we are performing a single operation on two numbers.

Another approach would be to convert the numerators and
denominators separately to Decimal, and then do

   a/b + c/d = (a*d + b*c) / (b*d)

using the usual rules of Decimal arithmetic. This would
incur more than one rounding, but the rules for Decimals
concern operations between two Decimals, and we have a
Decimal and a Fraction here, so all bets could be considered
off.

-- 
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4