Why does python break IEEE 754 for 1.0/0.0 and 0.0/0.0?

Tim Peters tim.peters at gmail.com
Thu Jul 14 20:31:57 EDT 2005


[Grant Edwards]
>> 1/0 is defined by the standard as +Inf and 0/0 is NaN.
 
[Martin v. Löwis]
> I wonder why Tim hasn't protested here:

Partly because this thread (unlike the other current thread on the
topic) isn't moving toward making progress, and I have little time for
this.

But mostly because Python's fp design was in no way informed by 754,
so logic-chopping on the 754 standard wrt what Python actually does is
plainly perverse <0.5 wink>.

> I thought this was *not* the case. I thought IEEE 754 defined +Inf and NaN
> as only a possible outcome of these operations with other possible
> outcomes being exceptions... In that case, Python would comply to IEEE
> 754 in this respect (although in a different way than the C implementation on
> the same system).

Ya, and Unicode defines 16-bit little-endian characters <wink>. 
Seriously, the 754 standard is quite involved, and there's just no
visible point I can see to trotting out its elaborate details here. 
If Python claimed to support 754, then details would be important. 
Short course wrt this specific point:  there's no reasonable way in
which Python's float arithmetic can be said to comply to IEEE 754 in
this case, neither in letter nor spirit.  The decimal module does,
though (mutatis mutandis wrt base).



More information about the Python-list mailing list