On Thu, Jun 19, 2014 at 9:31 PM, Joel Goldstick
<joel.goldst...@gmail.com> wrote:
> On Jun 19, 2014 7:05 AM, "Neal Becker" <ndbeck...@gmail.com> wrote:
>>
>> Can I change behavior of py3 to return nan for 0./0. instead of raising an
>> exception?
>
> There is no nan in python.

Yes, there is, but it's not normal to get it as a division result like that.

One way is to explicitly try/except:

try:
    result = operand_1 / operand_2
except ZeroDivisionError:
    result = float("nan")

You may also be able to use the fpectl module, if it's available on
your system. Alternatively, use either decimal.Decimal or one of the
numpy types, both of which give you more flexibility in error handling
than the inbuilt float type gives. If you're doing heavy computational
work in Python and expect exact IEEE floating point semantics, you
should probably be using numpy anyway.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to