From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: Improving JSON pretty printing, how to represent floats? Date: Fri, 5 Apr 2024 14:53:06 +0200 Message-ID: <55DE1457-04ED-4FDF-8EA5-45DE53B5271C@gmail.com> References: <87msq8w2zm.fsf@gmail.com> <86bk6o56np.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18932"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?Q?G=C3=A9za_Herman?= , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Apr 05 14:54:05 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rsj51-0004fV-Jy for ged-emacs-devel@m.gmane-mx.org; Fri, 05 Apr 2024 14:54:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rsj4S-0003ev-Oz; Fri, 05 Apr 2024 08:53:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rsj4D-0003bI-3a for emacs-devel@gnu.org; Fri, 05 Apr 2024 08:53:16 -0400 Original-Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rsj4A-0000ix-Sf; Fri, 05 Apr 2024 08:53:12 -0400 Original-Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2d6fc3adaacso26099691fa.2; Fri, 05 Apr 2024 05:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712321588; x=1712926388; darn=gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=xQnOPBiKLiOycUBNvIUE5QxZ6EEpoZTyEQfKPt90uJI=; b=WHVDD0GY58w6h3iVdqNw9D1T9L0dv5nupF2r/F74E395n/Nrjqnwwn6P/ac0GiR4Pt Nov+rNwZilSnFeH04QUKmgWa12/tnCt1ex0SgD/1pHSgEJXpRMoFQS+slkDVKx5kDBKA 71yYelgfPLTBPpnqTH+5ckGqhbmeXjN1OTF+MpszAqFLlJZc6YLGvpYseqAC6t3efMCf PH7zsTxKJxodcMHAgwXkuobEyhKbCva+bcfeMFDWQegidCeg2v9jhXV5wCoXBYOQvZXo s2qXW0rcKhmWu5hfchMSH3wUCAu/ez7f+ga5A0E/t6xPJJNr1OfcJerwc+jC1modQaq4 XynA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712321588; x=1712926388; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xQnOPBiKLiOycUBNvIUE5QxZ6EEpoZTyEQfKPt90uJI=; b=C7GBXodvyisWc46g3Huy41wwMOSJTAMlQtw695FWSi3eFChCHNdEchfp2jJUoYcFQK Bbk9WTdDIrkmJO2B4jHocOT+Dw0Gxzpwf5JhzE+mLvb3mEPmcP7aqsK3AoP0Q/sTjq/f AiaF6pN7ljXRvZYbdINUqtNicQ8c/S/LdTCf3LlUlRwIG8BUXsKNDDpQzFLjDIqF5G5B qWjhZWJzJYoAo+vU/ELAZETx2oElXUSQv/LVw4rb1YIPbD7io91X2pHtkFqmuCu1vUdF VUQk6W0lHheAKieYgS7TUXszqwdiBjFzsQjJI7vW0q5G4tCKYOZwbNU8P0gbRp0OInPn 0uSQ== X-Forwarded-Encrypted: i=1; AJvYcCU+7gklmvq6s2ybDQqH3SvfqzmvFKxT4OmZU/akUI54gXYRiLJXQOzLZlsX5izqwpoUfsaxdnxtRq99e1pT6ckVo5xN X-Gm-Message-State: AOJu0YxNn1NzWAqxnjjOLRMQQp5tn3bgnDhkAPwtNNdP9n47DqZM73Eq jQiErp/HxqgE4txEwDLLvZlgt9SJBKNRYOJuFTY4ouZeaYw1ZblcSHmFaKbQ X-Google-Smtp-Source: AGHT+IFQKtLgKIOdN5EHd6x/ZCLR9R0kygMcL0/9UKwkFpZENK3VT2z8riz26tzojteQfhxpc8cuHw== X-Received: by 2002:a05:651c:d2:b0:2d6:9e7a:1524 with SMTP id 18-20020a05651c00d200b002d69e7a1524mr993890ljr.13.1712321587806; Fri, 05 Apr 2024 05:53:07 -0700 (PDT) Original-Received: from smtpclient.apple (c80-217-1-132.bredband.tele2.se. [80.217.1.132]) by smtp.gmail.com with ESMTPSA id v9-20020a2e9609000000b002d6a40a26a5sm167139ljh.87.2024.04.05.05.53.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Apr 2024 05:53:07 -0700 (PDT) In-Reply-To: <86bk6o56np.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.120.0.1.15) Received-SPF: pass client-ip=2a00:1450:4864:20::230; envelope-from=mattias.engdegard@gmail.com; helo=mail-lj1-x230.google.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_SBL_A=0.1 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:317543 Archived-At: 5 apr. 2024 kl. 14.35 skrev Eli Zaretskii : >> --8<---------------cut here---------------start------------->8--- >> { >> "a": 3.333333333333000000000000000001 >> } >> --8<---------------cut here---------------end--------------->8--- >>=20 >> then the float gets rounded. I think pretty printing should be=20 >> lossless (keeping the exact format, exp notation, etc.). >=20 > 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/