[Python-Dev] VAX NaN evaluations

Steven D'Aprano steve at pearwood.info
Tue Nov 5 03:44:30 CET 2013

On Mon, Nov 04, 2013 at 08:47:53PM +0000, John Klos wrote:
> The short answer is to skip those tests on VAXen. The better answer is to 
> patch any isnan functions to always return false on VAXen and patch any 
> code which tries to parse, for instance, float("NaN") to use something 
> uncommon, such as the largest representable number (const union __double_u 
> __infinity = { { 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };) or 
> something else equally rare. While code which depends on the ability to 
> evaluate NaNs in some meaninful way will likely break on VAXen, I think 
> this is better than raising an exception.

(I take it that emulating NANs at the object level isn't an option? 
That's what the Decimal class does.)

I write code that uses NANs, and if running it on a VAX would break my 
code, I'd rather it broke it nice and cleanly with an exception rather 
than by just giving the wrong result.

With an exception, I can see straight away that something is wrong, and 
decide the best way to deal with the lack of NANs for my application. If 
you helpfully "fix" it for me by returning a non-NAN number, or even an 
infinity, at best I'll get a failure somewhere else in the application, 
far from where the break actually occurred; at worst, I may never know 
that my application is actually generating garbage results.

I'm reminded about a quote from Chris Smith:

"I find it amusing when novice programmers believe their main job is 
preventing programs from crashing. ... More experienced programmers 
realize that correct code is great, code that crashes could use 
improvement, but incorrect code that doesn’t crash is a horrible 

Not to imply that you're a novice programmer (sorry for the implication) 
but please don't do that to your users. The Zen of Python talks about 

py> import this
The Zen of Python, by Tim Peters

Errors should never pass silently.

Just to be clear, rather than dump core (which you suggested in a later 
email), if you cannot support NANs on VAXen, you should modify float to 
raise a ValueError exception. Pure Python code like float('nan') should 
never dump core, it should raise:

ValueError: could not convert string to float: 'nan'


More information about the Python-Dev mailing list