[Cbor] Re: nan'' application-extension literal
Carsten Bormann <cabo@tzi.org> Mon, 05 August 2024 19:02 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 CA641C1519AC for <cbor@ietfa.amsl.com>; Mon, 5 Aug 2024 12:02:12 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -6.909
X-Spam-Level:
X-Spam-Status: No, score=-6.909 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] 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 PEcXVwJMhoXd for <cbor@ietfa.amsl.com>; Mon, 5 Aug 2024 12:02:10 -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 C0BD2C14F5E8 for <cbor@ietf.org>; Mon, 5 Aug 2024 12:02:08 -0700 (PDT)
Received: from smtpclient.apple (p5dc5d809.dip0.t-ipconnect.de [93.197.216.9]) (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 4Wd5Qh5wsnzDCbk; Mon, 5 Aug 2024 21:02:04 +0200 (CEST)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <2711394.vuYhMxLoTh@tjmaciei-mobl5>
Date: Mon, 05 Aug 2024 21:01:54 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <B336E253-93A3-4E7F-8679-2F30D08D6385@tzi.org>
References: <65F1B2EE-DC84-438A-B3C6-943B153F3B08@tzi.org> <2711394.vuYhMxLoTh@tjmaciei-mobl5>
To: Thiago Macieira <thiago.macieira@intel.com>
X-Mailer: Apple Mail (2.3776.700.51)
Message-ID-Hash: M5DQ2TRDQWJGF6CGD55ETR2DJ2T3M4FO
X-Message-ID-Hash: M5DQ2TRDQWJGF6CGD55ETR2DJ2T3M4FO
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
X-Mailman-Version: 3.3.9rc4
Precedence: list
Subject: [Cbor] Re: nan'' application-extension literal
List-Id: "Concise Binary Object Representation (CBOR)" <cbor.ietf.org>
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/QAR4zp8TEfNnxYSdzhbE5QKDsFE>
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 5. Aug 2024, at 17:27, Thiago Macieira <thiago.macieira@intel.com> wrote: > > I suggest using something that can be fed right back to GCC's __builtin_nan() > intrinsic. That is, specify the hexadecimal pattern that the NaN payload bits > are carrying, not an hexafloat. That’s how I started to think about this, too. However, the designers of the C functions nanf() and nan() made separate functions for the two floating point sizes (they don’t support half size); these two are not compatible with each other. The reason appears to be that the designers didn’t understand that NaN payloads are left adjusted bit strings — we expect integer constants to be right adjusted (zero expand on left), not left adjusted (zero expand on right) like NaNs. The only standard hex format that I could find for zero expand on right is hex floats. E.g, 0x1.94p0 is "3f f9 40 00 00 00 00 00” in hex. The corresponding NaN (obtained by flipping the first bit of the exponent), “7f f9 40 00 00 00 00 00” as double, also is "7e 50” in half precision, or "7f CA 00 00” in single precision. These three sizes convert freely between each other. In my proposed notation, they all are represented as nan’0x1.94p0’. In C, I think they are something like nan(0x1400000000000) or nanf(0x4A0000). That doesn’t make a lot of sense if we try to express values independent of their representation size (and encourage preferred encoding). (The C language functions are also missing a way to create signaling NaNs.) Toggling the msb of the exponent (as in value.b[0] ^= 0x40) is much more likely to give you what you need than the inexplicable C language functions. Grüße, Carsten
- [Cbor] nan'' application-extension literal Carsten Bormann
- [Cbor] Re: nan'' application-extension literal Thiago Macieira
- [Cbor] Re: nan'' application-extension literal Carsten Bormann