Guarding arithmetic

Chris Angelico rosuav at gmail.com
Thu Aug 23 05:30:37 EDT 2012


On Thu, Aug 23, 2012 at 7:28 PM, Laszlo Nagy <gandalf at shopzeus.com> wrote:
>> 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 )

Thanks, that's the sort of thing I meant. I'm not familiar enough with
Python's floating point handler to know those details.

ChrisA



More information about the Python-list mailing list