Re: [Json] [Cbor] JSON and int64s - any change in current best practice since I-JSON

Carsten Bormann <cabo@tzi.org> Sat, 27 January 2024 14:37 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 6F76BC14CE27; Sat, 27 Jan 2024 06:37:02 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.407
X-Spam-Level:
X-Spam-Status: No, score=-1.407 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLACK=0.5, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=no autolearn_force=no
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pAF1XF3RrjXg; Sat, 27 Jan 2024 06:36:58 -0800 (PST)
Received: from smtp.zfn.uni-bremen.de (smtp.zfn.uni-bremen.de [IPv6:2001:638:708:32::21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 2964FC14F6B9; Sat, 27 Jan 2024 06:36:55 -0800 (PST)
Received: from eduroam-0298.wlan.uni-bremen.de (eduroam-0298.wlan.uni-bremen.de [134.102.17.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.zfn.uni-bremen.de (Postfix) with ESMTPSA id 4TMcZr6f3SzDCdd; Sat, 27 Jan 2024 15:36:52 +0100 (CET)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <0C97FF67-A3D4-44EC-BD17-AC1F7A2BA9A2@cursive.net>
Date: Sat, 27 Jan 2024 15:36:52 +0100
Cc: "json@ietf.org" <json@ietf.org>, cbor@ietf.org, Tim Bray <tbray@textuality.com>
X-Mao-Original-Outgoing-Id: 728059012.2425931-2d963b29e4b12daa6c9318e48f6b43fc
Content-Transfer-Encoding: quoted-printable
Message-Id: <80D3667A-BC74-4197-BBBC-2B7B9D478D34@tzi.org>
References: <87527a42-aaac-4f39-b320-05f18a2808c1@codalogic.com> <C31BF4C8-9E6C-48F8-BF7B-D2C379273B3F@tzi.org> <CAHBU6it4SaLawSiBgK9ySkbxjtHE6CX-P3r=hzcVy4ksoQo-Cg@mail.gmail.com> <CAChr6SxHfLW-A1asAndKJz-AiyJv5QP18bi=_bNdKXw7zYHThw@mail.gmail.com> <CAChr6SweYdCWxSABZ7g20Zd-xBFzcK0Ritq53S7WtjSwc-vLmw@mail.gmail.com> <E5A68370-CC2F-4618-AB39-39A382656616@cursive.net> <807fea1b-a22b-4d6b-aa5d-720c9b12023c@codalogic.com> <09233A73-3A6B-4E6F-AEB8-596AC6442E24@cursive.net> <869950DC-647B-4481-AEF8-9E092384E99F@tzi.org> <CBD32B58-8328-4602-89C6-BC2A7A875A0D@cursive.net> <994E2C0A-4AE0-4720-8C67-913BBF033E11@tzi.org> <0BB09B30-B606-44CC-85DC-95A47E485316@cursive.net> <B22EDB2D-0AD1-4582-9191-EFB40E163F19@tzi.org> <F6EB02CA-C240-4FA1-92A8-C5BB883929C7@cursive.net> <29BD1557-59A1-4578-901B-C626ABBE9A78@tzi.org> <B25E10D2-17CF-4B3D-B04B-BABE3A209B90@cursive.net> <6A73993B-B54D-480D-AF79-081EE9D2E1C8@cursive.net> <94BD8ECC-0D50-4C09-9B29-7552AFC4D9ED@tzi.org> <0C97FF67-A3D4-44EC-BD17-AC1F7A2BA9A2@cursive.net>
To: Joe Hildebrand <hildjj@cursive.net>
X-Mailer: Apple Mail (2.3608.120.23.2.7)
Archived-At: <https://mailarchive.ietf.org/arch/msg/json/G5_AQmMWGgt941otlIBN0VSHqMg>
Subject: Re: [Json] [Cbor] JSON and int64s - any change in current best practice since I-JSON
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <json.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/json>, <mailto:json-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/json/>
List-Post: <mailto:json@ietf.org>
List-Help: <mailto:json-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/json>, <mailto:json-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Jan 2024 14:37:02 -0000

On 2024-01-25, at 16:20, Joe Hildebrand <hildjj@cursive.net> wrote:
> 
>> * leading/trailing decimal points.  What is the semantics that need to be defined here?
> 
> For leading, probably none.  For trailing, it might be a sign that the number should be treated as floating point, so that there is a difference between `1` and `1.` in environments where there are different types for float and int.  At the very list, the range checking should be different.

Right.
It seems programming languages like Python, JavaScript, Java, C, C++, and FORTRAN allow leaving off all-leading- or all-trailing-zeros in the mantissa (but not both), clearly still treating the number as a floating point value.
This is also part of IEEE 754 5.12.2 “External character sequences” syntax (Section 5.12), and was already in ECMA-63 NR2/NR3 (which became ISO 6093 later).

However, this is not universally supported; a few quick examples (not thoroughly checked, please correct where wrong):
* C# allows eliding all leading zeroes, but not all trailing zeros, 
* Rust allows eliding all trailing zeroes, but not all leading zeros,
* Ruby allows neither.

Supporting full FORTRAN syntax here therefore is a bit against my personal style, but I gather I might be in the rough with this against massive historical precedent.

PR in [0], [1], with formatted version at [2], [3].

[0]: https://github.com/cbor-wg/edn-literal/pull/29
[1]: https://github.com/cbor-wg/edn-literal/pull/29/files
[2]: https://cbor-wg.github.io/edn-literal/elide-zero-mantissa-parts/draft-ietf-cbor-edn-literals.html#name-overall-abnf-definition-for
[3]: https://cbor-wg.github.io/edn-literal/elide-zero-mantissa-parts/draft-ietf-cbor-edn-literals.html#appendix-A.1-7.1.1

You can play with this using edn-abnf 0.1.5 (gem update edn-abnf):

edn-abnf -tedn -e +2.
edn-abnf -tedn -e +.2
edn-abnf -tedn -e +.
edn-abnf -tedn -e +2.e2
edn-abnf -tedn -e +.2e2
edn-abnf -tedn -e +.e2

Oh, and while fiddling with this, I found a bug:
The -07 EDN syntax allowed 0x1.3p (zero length exponent), which really needs to be 0x1.3p0.
Fixed in [4] (and included in edn-abnf 0.1.4 and the above formatted text version).

[4]: https://github.com/cbor-wg/edn-literal/commit/6096deb

Grüße, Carsten