[Python-Dev] Not-a-Number (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Fri Apr 29 08:35:21 CEST 2011
- Previous message: [Python-Dev] Not-a-Number
- Next message: [Python-Dev] Not-a-Number
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] Not-a-Number
- Next message: [Python-Dev] Not-a-Number
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]