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/098695.html below:

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

[Python-Dev] Mixing float and Decimal -- thread rebootGuido van Rossum guido at python.org
Mon Mar 22 20:03:04 CET 2010
On Mon, Mar 22, 2010 at 11:00 AM, Raymond Hettinger
<raymond.hettinger at 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.

Works for me.

-- 
--Guido van Rossum (python.org/~guido)
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