Decimal vs float
Steve Holden
steve at holdenweb.com
Fri Jan 20 22:48:26 EST 2006
Steven D'Aprano wrote:
> On Fri, 20 Jan 2006 04:25:01 +0000, Bengt Richter wrote:
>
>
>>On Thu, 19 Jan 2006 12:16:22 +0100, =?ISO-8859-1?Q?Gerhard_H=E4ring?= <gh at ghaering.de> wrote:
>>[...]
>>
>>>floating points are always imprecise, so you wouldn't want them as an
>>
>>Please, floating point is not "always imprecise." In a double there are
>>64 bits, and most patterns represent exact rational values. Other than
>>infinities and NaNs, you can't pick a bit pattern that doesn't have
>>a precise, exact rational value.
>
>
> Of course every float has a precise rational value.
> 0.1000000000000000000001 has a precise rational value:
>
> 1000000000000000000001/10000000000000000000000
>
> But that's hardly what people are referring to. The question isn't whether
> every float is an (ugly) rational, but whether every (tidy) rational is a
> float. And that is *not* the case, simple rationals like 1/10 cannot be
> written precisely as floats no matter how many bits you use.
>
>
>>You can't represent all arbitarily chosen reals exactly as floats, that's true,
>>but that's not the same as saying that "floating points are always imprecise."
>
>
> "Always" is too strong, since (for example) 1/2 can be represented
> precisely as a float. But in general, for any "random" rational value N/M,
> the odds are that it cannot be represented precisely as a float. And
> that's what people mean when they say floats are imprecise.
>
>
>
And you thought Bengt didn't know that?
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list