[Python-ideas] math.nexttoward, math.ulp, etc.

Andrew Barnert abarnert at yahoo.com
Sat Jan 24 04:57:47 CET 2015

Some of this has come up multiple times in the discussion of the is_close_to PEP and the math.nan idea, but I think it's actually a separate issue.

I think it might be worth adding some of the following to math:

 * isnormal (like C)
 * nextafter/nexttoward (like C) and/or nextplus/nextminus (like decimal)
 * bitdifference (inverse of nexttoward)
 * ulp (like Java)
 * signbit (like C)
 * isqnan, issnan (like decimal)
 * makenan(payload, quiet=True, sign=False) and nanpayload(f)
 * as_tuple and from_tuple (like decimal--although of course the tuple isn't quite the same)

In some cases, it would be perfectly reasonable for these functions to only be available on, e.g., Windows (maybe even only NT, not CE) plus any platform that confirms to either C99 or POSIX-2001 (which includes almost all non-Windows platforms you're likely to run into nowadays), or only on platforms that use IEEE 754-2008 or Intel-style IEEE 754-1985 (again, almost everything), etc., as appropriate; no need to try to implement them all fully generally from scratch for any C89 platform just in case someone decides to build Python 3.5 for 68k A/UX or something.

More information about the Python-ideas mailing list