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

Carsten Bormann <cabo@tzi.org> Wed, 21 August 2024 10:00 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 D98FBC14F605 for <cbor@ietfa.amsl.com>; Wed, 21 Aug 2024 03:00:33 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -6.895
X-Spam-Level:
X-Spam-Status: No, score=-6.895 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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01, URIBL_BLOCKED=0.001, 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 pvn6GG9ZsRq9 for <cbor@ietfa.amsl.com>; Wed, 21 Aug 2024 03:00:25 -0700 (PDT)
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 ECDSA (P-256) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 417C2C14F600 for <cbor@ietf.org>; Wed, 21 Aug 2024 03:00:06 -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 4Wphdl2Ln4zDCbL; Wed, 21 Aug 2024 11:59:55 +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: <17c394aa-095b-4a6d-95ee-0741b6b166f8@gmail.com>
Date: Wed, 21 Aug 2024 11:59:54 +0200
X-Mao-Original-Outgoing-Id: 745927194.719013-6af6dc27f2f2c995cc63a0c17daadc27
Content-Transfer-Encoding: quoted-printable
Message-Id: <2869DB6E-61BD-42D8-80B4-AA909C978B56@tzi.org>
References: <17c394aa-095b-4a6d-95ee-0741b6b166f8@gmail.com>
To: Anders Rundgren <anders.rundgren.net@gmail.com>
X-Mailer: Apple Mail (2.3608.120.23.2.7)
Message-ID-Hash: DLFULFIBHUR73DQE62Q4AUHMIIFZ33YZ
X-Message-ID-Hash: DLFULFIBHUR73DQE62Q4AUHMIIFZ33YZ
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/g0YVnJfIUAK3UGdh0PJbd7txymQ>
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 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)

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

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

> 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.  
Do you mean:

https://www.ietf.org/archive/id/draft-ietf-cbor-cde-05.html#appendix-A-7

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

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

Grüße, Carsten