[Python-Dev] Not-a-Number

Nick Coghlan ncoghlan at gmail.com
Fri Apr 29 08:35:21 CEST 2011


On Fri, Apr 29, 2011 at 3:28 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Robert Kern wrote:
>> Actually, Python treats all NaNs as quiet NaNs and never signalling NaNs.
>
> Sorry, did I get that backwards? I thought it was signalling NANs that cause
> a signal (in Python terms, an exception)?
>
> If I do x = 0.0/0 I get an exception instead of a NAN. Hence a signalling
> NAN.

Aside from the divide-by-zero case, we treat NaNs as quiet NaNs. This
is largely due to the fact float operations are delegated to the
underlying CPU, and SIGFPE is ignored by default. You can fiddle with
it either by building and using the fpectl module, or else by
switching to decimal.Decimal() instead (which offers much finer
control over signalling through its thread local context information).
The latter is by far the preferable course, unless you're targeting
specific hardware with well-defined FPE behaviour.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list