Guarding arithmetic
Laszlo Nagy
gandalf at shopzeus.com
Thu Aug 23 05:28:56 EDT 2012
> That can work ONLY if the division of 1/0 doesn't raise an exception.
> This is why the concept of NaN exists; I'm not sure if there's a way
> to tell Python to return NaN instead of bombing, but it's most likely
> only possible with floating point, not integer.
For integers, Python will always raise an exception when you try to
divide by zero. And integers has nothing to do with NaN. Because NaN is
meaningful for floating point numbers only. Python can be compiled to
raise floating point exceptions. (On Python 2, this is a compile time
option: FPECTL. On Python 3, this can be configured runtime:
http://docs.python.org/library/fpectl.html )
More information about the Python-list
mailing list