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

Grant Edwards grante at visi.com
Thu Jul 14 20:44:46 CEST 2005


I've read over and over that Python leaves floating point
issues up to the underlying platform.  

This seems to be largely true, but not always.  My underlying
platform (IA32 Linux) correctly handles 1.0/0.0 and 0.0/0.0
according to the IEEE 754 standard, but Python goes out of its
way to do the wrong thing.

1/0 is defined by the standard as +Inf and 0/0 is NaN.

That's what my platform does for programs written in C.  Python
apparently checks for division by zero and throws and exception
rather than returning the correct value calculated by the
underlying platform.

Is there any way to get Python to return the correct results
for those operations rather than raising an exception?

There's no way to "resume" from the exception and return a 
value from an exception handler, right?  [This is the other
option allowed by the IEEE 754 standard.]

-- 
Grant Edwards                   grante             Yow!  ... I want a COLOR
                                  at               T.V. and a VIBRATING BED!!!
                               visi.com            



More information about the Python-list mailing list