all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattias.engdegard@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: "Géza Herman" <geza.herman@gmail.com>, emacs-devel@gnu.org
Subject: Re: Improving JSON pretty printing, how to represent floats?
Date: Fri, 5 Apr 2024 14:53:06 +0200	[thread overview]
Message-ID: <55DE1457-04ED-4FDF-8EA5-45DE53B5271C@gmail.com> (raw)
In-Reply-To: <86bk6o56np.fsf@gnu.org>

5 apr. 2024 kl. 14.35 skrev Eli Zaretskii <eliz@gnu.org>:

>> --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.

The float printer we use tries to produce the shortest output that, when read back in using IEEE-754 64-bit floats and the default rounding mode, results in the same number. There is no loss of information.

The JSON specs mandate little about range and precision for numbers and implementations indeed vary a lot; see [1] for a recent overview. However given its Javascript origins and the prevalence of 64-bit floats, we are pretty safe here for anything that doesn't have very special requirements (such as decimal FP). Our support for arbitrary big integers is more than many other implementations do.

[1] https://blog.trl.sn/blog/what-is-a-json-number/




  reply	other threads:[~2024-04-05 12:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05  9:39 Improving JSON pretty printing, how to represent floats? Herman, Géza
2024-04-05 12:35 ` Eli Zaretskii
2024-04-05 12:53   ` Mattias Engdegård [this message]
2024-04-05 12:55   ` Herman, Géza
2024-04-05 13:09     ` Eli Zaretskii
2024-04-05 13:16       ` Herman, Géza
2024-04-05 14:01         ` tomas
2024-04-05 15:34         ` Eli Zaretskii
2024-04-05 16:46           ` Herman, Géza
2024-04-05 13:37 ` Dmitry Gutov
2024-04-05 14:20   ` Herman, Géza
2024-04-05 16:47     ` Dmitry Gutov
2024-04-05 14:18 ` Mattias Engdegård
2024-04-05 14:25   ` Herman, Géza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55DE1457-04ED-4FDF-8EA5-45DE53B5271C@gmail.com \
    --to=mattias.engdegard@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=geza.herman@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.