[Python-Dev] Mixing float and Decimal -- thread reboot
Jeffrey Yasskin
jyasskin at gmail.com
Sun Mar 21 00:27:54 CET 2010
On Sat, Mar 20, 2010 at 4:20 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Adam Olsen wrote:
>
>> For a little context, we have this numeric tower:
>>
>> int -> Fraction -> float -> complex
>>
>> Decimal is more precise, and pays a performance cost for it. It also
>> seems odd to stick it between float and complex (nobody's planning a
>> ComplexDecimal, right?) That suggests it should go between Fraction
>> and float. Decimal/float -> float.
>
> There are two ways in which that linear tower is overly
> simplistic:
>
> * It conflates the notions of exactness and width. They're
> really orthogonal concepts, and to reflect this you would
> need two parallel towers, with exact and inexact versions
> of each type.
It's representing the mathematical concepts
Integral -> Rational -> Real -> Complex
When designing it, I tried to include a notion of exact/inexact types,
but we couldn't find anything practical to do with them, so we took
them out. It's reasonably easy to design inexact Integral and Rational
types, but pretty hard to design a useful, exact Real type (things
like '==' get uncomputable quickly), so we probably couldn't actually
implement two whole parallel towers.
> * Decimal and float really belong side-by-side in the
> tower, rather than one above the other.
Yep.
More information about the Python-Dev
mailing list