On Sun, Dec 29, 2019 at 11:21:51PM -0500, David Mertz wrote:

> Has anyone actually ever used those available bits for the zillions of NaNs
> for anything good?

Absolutely.

Back in the 1980s, Apple released one of the first (if not the 
first) IEEE-754 compliant maths library: SANE, the Standard Apple 
Numerics Environment.

SANE used the NAN payload to encode diagnostic information on the kind 
of failure. For example, a payload of 1 was an invalid sqrt; a payload 
of 17 was an invalid string to float conversion; a payload of 34 was an 
invalid argument to an inverse trig function. I can tell you from 
personal experience that this was quite useful although not a panacea.

For 64-bit floats, there are 51 bits available for the NAN payload. 
That's enough for a seven ASCII character message, or to encode (say) a 
7 bit error code and 44 bits for a line number, or whatever information 
you need to allow the compiler to identify the source of the error.

Javascript does a horrible/awesome (choose one) hack called "NAN 
boxing":

https://anniecherkaev.com/the-secret-life-of-nan

There's at least one Ada project that encodes tagged data in NANs:

http://dan.corlan.net/software/nan_payload/

Unfortunately, indifferent support for NAN payloads by many compilers 
and languages has lead to developers neglecting NAN payloads, and lack 
of developer use for payloads leads to poor compiler support.

-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/73M3Q6Q2KB7CB5GYUHSCZPB3ANAGPPVW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to