On Wed, Jun 17, 2020 at 05:06:29PM +1000, Chris Angelico wrote:

> > In Javascript:
> >
> >     js> typeof(NaN)
> >     number
> >     js> typeof(Infinity)
> >     number
> >
> > Odd as it may seem, NANs and INFs are numbers. And the JSON standard
> > isn't capable of encoding them. The JSON standard defines "number" in
> > such a way that even in the language that originated JSON, it can't
> > represent all numbers.
> >
> 
> That's JavaScript you're looking at, not JSON.

Yes I know. You can tell I already knew that, by the way I explicitly 
referred to Javascript, sometimes I'm quite clever like that :-)


> The JSON standard never
> says anything about IEEE floats. You said the words "supported type"
> and clearly implied IEEE floats, complete with infinity and nan, but
> that is not what the standard says. The "supported type" in JSON is
> simply a string of digits, optionally with a decimal point and/or an
> exponent. That is all.

You're technically correct, which is the best kind of correct, apart 
from missing out on negatives :-)

Nevertheless, JSON fails to support things which are considered numbers 
by Javascript and other languages, such as those little-known exotic 
languages Java, C/C++, PHP, and Python, you might have heard of them :-)

We're not arguing about exotic numeric types like quaternions or complex 
numbers or even fractions. We're talking about the JSON standard not 
even being able to fully support probably the single most common 
floating point numeric types in the world. That doesn't strike you as a 
bit broken? Not even a little bit?

The JSON standard didn't just accidently fail to specify what to do with 
NANs and INFs. It mandates that they are turned into null. JSON is 
designed to take your numeric data and throw values away, and this is a 
real problem for people:

https://github.com/dotnet/runtime/issues/31024

https://github.com/AppMetrics/AppMetrics/issues/502

which is probably why a lot of JSON implementations provide support for 
INFs and NANs no matter what the standard says.

The bottom line here is that the JSON definition of "number" fails to 
match numeric data types in not just other languages like Python, but 
even in Javascript.


-- 
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/GZV3O25ZT63LTCZYOK5G6YAZ4JRGBRY5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to