I never said it was, he specifically said as an aside for a book he was writing. He said he hadn't heard of code using it, so I provided an example
You are talking about an *internal implementation detail* in the C code
I never claimed there was, just that that was a use case of tagged nans, was common for JS engine implementers to use, and indeed was a use case in which inspecting the payload bits and having unique nan values was relevant.
Imagine that a Python program would use a `libc` binding (for example, C-types) to interface with such an engine. It would have to be able to differentiate. Obviously, there are good reasons Python doesn't support it, and people shouldn't grow to expect it, and this isn't really relevant to the discussion (insofar as the PEP proposed doesn't specify that 'inf' and 'nan' be treated as singletones, just as default builtins).
This would become relevant, if, say Python 4.0 migrated 'inf' and 'nan' to builtin names (like True and False). If that happened, a 'nan' singleton wouldn't make sense unless you had 2**53 of them, so code like:
x is nan
Would be a flawed formulation
Thanks, ---- *Cade Brown* Research Assistant @ ICL (Innovative Computing Laboratory) Personal Email: email@example.com ICL/College Email: firstname.lastname@example.org
On Sun, Sep 13, 2020 at 8:57 PM Steven D'Aprano email@example.com wrote:
On Sat, Sep 12, 2020 at 08:16:36PM -0400, Cade Brown wrote:
Aside from the extra complexity, which may or may not pay off in speed improvements, the downside of NAN boxing is the serious security hole that if you can introduce an arbitrary NAN value into a JS primitive value, you get a pointer to arbitrary memory and can use that to get up to all sorts of shenanigans.
To avoid that security hole, JS has to normalise all incoming NANs to a single canonical NAN (thus, losing any possibility of user code making use of NAN payloads).
In CPython's case, the interpreter uses pointers as object references, not the payload bits of a NAN. Jython and IronPython use whatever the JVM and .Net CLR use, which probably isn't NANs either.
So while NAN boxing is a clever use of NAN payloads, it's not really relevant here. Python code doesn't have a notion of pointers to arbitrary addresses, but if it did, user code probably wouldn't have to manipulate the payload bits of a NAN float object to get one.
-- Steve _______________________________________________ Python-ideas mailing list -- firstname.lastname@example.org To unsubscribe send an email to email@example.com https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://firstname.lastname@example.org/message/54RN6H... Code of Conduct: http://python.org/psf/codeofconduct/