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: Herman , Géza
Subject: Re: Improving JSON pretty printing, how to represent floats?
Date: Fri, 05 Apr 2024 14:55:26 +0200


Eli Zaretskii <eliz@gnu.org> writes:

From: Herman, Géza <geza.herman@gmail.com>
Date: Fri, 05 Apr 2024 11:39:10 +0200

There is a thing that I don't like about the current
json-pretty-print: as it parses floats, pretty printing can be
lossy.  If one pretty prints this

--8<---------------cut here---------------start------------->8---
{
    "a": 3.333333333333000000000000000001
}
--8<---------------cut here---------------end--------------->8---

then the float gets rounded.  I think pretty printing should be
lossless (keeping the exact format, exp notation, etc.).

The digits in 3.333333333333000000000000000001 after 16th digit are meaningless: they aren't supported by IEEE floating-point standard, so they are just numerical noise. Thus, talking about "lossless" wrt
them makes little sense to me.

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.



reply via email to

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