[Cbor] Re: Dealing with -0.0, NaN, and Infinity

Carsten Bormann <cabo@tzi.org> Wed, 21 August 2024 12:43 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 0D685C14F5EA for <cbor@ietfa.amsl.com>; Wed, 21 Aug 2024 05:43:33 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -6.907
X-Spam-Level:
X-Spam-Status: No, score=-6.907 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham 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 GphgRKKE5A75 for <cbor@ietfa.amsl.com>; Wed, 21 Aug 2024 05:43:29 -0700 (PDT)
Received: from smtp.zfn.uni-bremen.de (smtp.zfn.uni-bremen.de [134.102.50.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 202B7C14F60A for <cbor@ietf.org>; Wed, 21 Aug 2024 05:43:28 -0700 (PDT)
Received: from clients-pool1-0074.vpn.uni-bremen.de (clients-pool1-0074.vpn.uni-bremen.de [134.102.107.74]) (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 4WpmGP5kXZzDCbl; Wed, 21 Aug 2024 14:43:25 +0200 (CEST)
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: <fcdf23a9-fb0f-48d2-b141-dce1d634b6d9@gmail.com>
Date: Wed, 21 Aug 2024 14:43:25 +0200
X-Mao-Original-Outgoing-Id: 745937005.177546-0daf2ea9c3e9ebb6319cfda24405befc
Content-Transfer-Encoding: quoted-printable
Message-Id: <193D8044-AFBD-4C67-914C-7C17918C077D@tzi.org>
References: <17c394aa-095b-4a6d-95ee-0741b6b166f8@gmail.com> <2869DB6E-61BD-42D8-80B4-AA909C978B56@tzi.org> <fcdf23a9-fb0f-48d2-b141-dce1d634b6d9@gmail.com>
To: Anders Rundgren <anders.rundgren.net@gmail.com>
X-Mailer: Apple Mail (2.3608.120.23.2.7)
Message-ID-Hash: 4UMLXU7X4BWVOQEWL3EGIBAJPDJHK2O4
X-Message-ID-Hash: 4UMLXU7X4BWVOQEWL3EGIBAJPDJHK2O4
X-MailFrom: cabo@tzi.org
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-cbor.ietf.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
CC: "cbor@ietf.org" <cbor@ietf.org>
X-Mailman-Version: 3.3.9rc4
Precedence: list
Subject: [Cbor] Re: Dealing with -0.0, NaN, and Infinity
List-Id: "Concise Binary Object Representation (CBOR)" <cbor.ietf.org>
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/X_6uztZsu7KO0DT24yhUwnUJmNg>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Owner: <mailto:cbor-owner@ietf.org>
List-Post: <mailto:cbor@ietf.org>
List-Subscribe: <mailto:cbor-join@ietf.org>
List-Unsubscribe: <mailto:cbor-leave@ietf.org>

On 2024-08-21, at 12:44, Anders Rundgren <anders.rundgren.net@gmail.com> wrote:
> 
> On 2024-08-21 11:59, Carsten Bormann wrote:
>> On 2024-08-21, at 11:42, Anders Rundgren <anders.rundgren.net@gmail.com> wrote:
>>> 
>>> When trying to define a subset of CBOR CDE suitable as a JSON replacement
>> ➔ “a CDE application profile”  (fixed that for you)
> 
> Right but since the proposal is an API, there is no apparent need for a separate application profile:
> https://cyberphone.github.io/CBOR.js/doc/#main.wrappers

The point of identifying your work as an application profile is that we know a few things about application profiles now and can look at your work based on that knowledge.

> In addition, given the lukewarm interest in this project and its objectives, where would such a profile be developed?

There is no limitation on who can develop a CDE application profile and where.
The important thing here is recognizing that you are doing that and make use of the above mentioned knowledge.

>>> Although -0.0, NaN, and Infinity probably have very limited relevance in the intended target market, they must still be dealt with in some way.  The easy way is of course to just ban them during decoding.
>> Which an application profile can do in its set of exclusions.
> 
> Sure.
> 
> 
>>> FWIW, these are my current suggestions:
>>> 
>>> Following IEEE 754 rules it seems that -0.0 does not interfere with normal operations including comparisons; it is still treated as 0.0. So it is currently supported "as is".
>> (The current text in CDE does not address decode-time reductions, as they don’t make sense for deterministic encoding — that must necessarily round-trip, so all reductions are encode-time.)
> 
> In this particular case there is no reduction.  -0.0 is supported as specified by CDE.

Good.

>>> However, since mathematical operations using NaN and Infinity are somewhat less nice, and typically indicate that something is fundamentally wrong, their support is currently made optional: https://cyberphone.github.io/CBOR.js/doc/#decoder.cbor.initextended
>> I don’t know what “optional” means.
> 
> You probably did not look into the supplied link.

Optional = a set of related, but separate application profiles (which you can also think as an application profile with options).

>> Do you mean:
>> https://www.ietf.org/archive/id/draft-ietf-cbor-cde-05.html#appendix-A-7
> 
> 
> Probably not.  For platform-wide solutions, run-time, per application options, is the only realistic way dealing with profiling of any kind.

That may very well be, but I still think that paragraph applies here.

> If you take a peek into https://cyberphone.github.io/CBOR.js/doc/#decoder.cbor.initextended you will find other options that may be needed.  You'll find then in https://cbor.me as well :)
> 
> 
>>> NaN with payloads are always rejected.  It is still a "strict subset" :)
>> All NaNs have payloads.
>> I think you are talking about payloads that are non-zero.
>> You should probably also exclude negative NaNs, then.
> 
> Yeah, the proposed API and associated encoding scheme only supports a single NaN variant. 0xfe00 to be more precise.

That is a widely implemented restriction, so I think this is a good choice.

>>> Related: since the JavaScript "JSON" object never became compatible with Open API number requirements, this became a core priority for "CBOR": https://cyberphone.github.io/CBOR.js/doc/#cbor.int.getint64
>> With a (presumably model-guided) pull-parser it is of course much easier to deal with the JavaScript number system.  I don’t get the question here, though.
> 
> There is no question, it just emphasizes how an ES "CBOR" object could be a better mousetrap than the current ES "JSON" object.  It is called "marketing" :)

Ah.  Certainly adding direct support (i.e., outside of other libraries that already need it) for CBOR to JavaScript would make a lot of sense.
BTW, I don’t think adding a ton of booleans to a constructor is a great way to handle different application requirements here (and describing the normal, non-CDE case by the “marketing” word “lenient” also doesn’t help).

Grüße, Carsten