emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Improving JSON pretty printing, how to represent floats?


From: Eli Zaretskii
Subject: Re: Improving JSON pretty printing, how to represent floats?
Date: Fri, 05 Apr 2024 18:34:42 +0300

> From: Herman, Géza <geza.herman@gmail.com>
> Cc: Géza Herman <geza.herman@gmail.com>,
>  emacs-devel@gnu.org
> Date: Fri, 05 Apr 2024 15:16:44 +0200
> 
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> You mean the 64-bit binary format. IEEE-754 describes more
> >> formats which have more precision, and also there are more
> >> formats used in practice than what IEEE-754 describes.
> >>
> >> Plus, I don't think that the JSON standard mandates IEEE-754
> >> numbers.  It just describes numbers, so I think it's good
> >> behavior to not change numbers during formatting.
> >
> > The fact that Emacs supports IEEE-754 on almost all platforms is
> > prominently documented in the ELisp reference manual, see the node
> > "Float Basics" there.
> 
> I don't think it's relevant here.

It is relevant to me, because a float in a JSON has a meaning, it
isn't just a string.  If you want strings, use strings, and then they
will not be changed by pretty-printing.

> If I reformat a JSON, it should really be a formatting operation, it
> shouldn't matter what kind of floating point numbers a platform
> supports.

Any JSON that uses a float which needs more than 64 bits of precision
is not portable to most of today's machines.  I'm not interested in
complicating Emacs to support imaginary use cases, sorry.  When enough
important platform switch to more bits of precision, so will we, and
then we will be able to have more digits in floats -- but even then
the number of significant digits will be finite.

> What if I open a .json file because I want to edit it a little bit
> (renaming some members, etc.), but then I realize that the format of
> the json is bad, so I reformat it.  But I want to maintain the
> precision, because I intend to use the .json in some other software
> which supports arbitrary floating point precision.

Well, you can't.  It makes no sense.  Floats are objects with certain
semantics, they are not just arbitrary strings.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]