Re: [Cbor] Implementing float->int numeric reduction

Anders Rundgren <anders.rundgren.net@gmail.com> Wed, 16 August 2023 07:00 UTC

Return-Path: <anders.rundgren.net@gmail.com>
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 0A52EC151700 for <cbor@ietfa.amsl.com>; Wed, 16 Aug 2023 00:00:25 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.196
X-Spam-Level:
X-Spam-Status: No, score=-2.196 tagged_above=-999 required=5 tests=[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, NICE_REPLY_A=-0.091, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
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 8KdPSnNO83u4 for <cbor@ietfa.amsl.com>; Wed, 16 Aug 2023 00:00:21 -0700 (PDT)
Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 4BA43C1522BE for <cbor@ietf.org>; Wed, 16 Aug 2023 00:00:16 -0700 (PDT)
Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fe2048c910so57161625e9.1 for <cbor@ietf.org>; Wed, 16 Aug 2023 00:00:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692169215; x=1692774015; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kiteu/VPHJloqW4NS2wPRTtM5JCVG6vD5A+M+i07dqw=; b=YYeZyMU82GVeDYroAq7EP7wokUXrLphCTAavuxt4QqGre3oQV2sIwI9eTIvKMqYvdG hvcYeYPCVFtLZR41UtYcFNKTzn07hWIOnRV4Sf+Qb1ihCav8ul7CkC5/gyUtwMulg536 jcfJjmLE1P0kiezG3BasV6kJmGCw38O3NYLz5vdQ2WQ9Ch85wovnfBLAKieRlC3XLy7X USt1uDRxrRRv1YF89SS6AHNlxsqr512o9OdhtDoA1O9j68ZWjLLAtOwVNj1WhOyr/anh bUm9PiiYwytox67Em1Eoa8noiuE5Nj4o+Q0CseiEZ6MAuyM7tY5C1QkZecOTIrVyLlSo UjyQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692169215; x=1692774015; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kiteu/VPHJloqW4NS2wPRTtM5JCVG6vD5A+M+i07dqw=; b=Uq7tQTYC3tqruZMFi9uPcMn/IaDNQ5Nx21IkC2ixHC3JY7DfFiA9RBgLZroknQ+7LR 1zkAl2dZ35F1/FrtIBvowK5EEf0WUHHrTT+wDmGqqSQ5/58Sv8EMypKeRyo6H/d3q94/ kYyroz7LvPdZrTbXxcOPQpJBFlQrIVhLgwiXpCiTOGNQJDtYLhBpcK1SmW+Ou9e/sKc8 gHJxRlsT2qq7yB6EObLLWJV29Nl3WCpflqkfctXBrW0OWRu9lSsmgHSNwMby0Ep4NSCL +OApXV7xhce5KkUNX5H6u7132CKXmgNRamMR1MRf3bwgvrIa3zNbTOd/HekzNqBSQdX0 PYJA==
X-Gm-Message-State: AOJu0YwtJYUsBD5dKMBrj731MFwETJ3CCQcUUoT9wQBzk4PBCIuJD6/W E+8Z2B8Wz+1YLWNr6U/EGvAkdC4I0ZY=
X-Google-Smtp-Source: AGHT+IFxZc2FfIY4xKBpNcvpThu1tHoTGuNK5FG6DMxCJaK1UKMVBmyaF5+XVNwrKrt5WcgF5xBZPw==
X-Received: by 2002:a1c:7711:0:b0:3fc:f9c:a3e6 with SMTP id t17-20020a1c7711000000b003fc0f9ca3e6mr819088wmi.9.1692169214389; Wed, 16 Aug 2023 00:00:14 -0700 (PDT)
Received: from ?IPV6:2a01:e34:ec4e:5670:ec72:5435:cd62:bd81? ([2a01:e34:ec4e:5670:ec72:5435:cd62:bd81]) by smtp.googlemail.com with ESMTPSA id v14-20020a1cf70e000000b003fe24441e23sm20080250wmh.24.2023.08.16.00.00.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Aug 2023 00:00:13 -0700 (PDT)
Message-ID: <ad728706-0707-dad1-5380-20790a3fffac@gmail.com>
Date: Wed, 16 Aug 2023 09:00:13 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0
Content-Language: en-US
To: Wolf McNally <wolf@wolfmcnally.com>
Cc: "lgl island-resort.com" <lgl@island-resort.com>, "cbor@ietf.org" <cbor@ietf.org>, Shannon Appelcline <shannon.appelcline@gmail.com>, Christopher Allen <christophera@lifewithalacrity.com>
References: <0EBCC710-F7BA-474E-8A6D-D67015FD5EC7@island-resort.com> <dd9bc427-31a7-6d51-2fb1-d02e1b2824ff@gmail.com> <BEAFD785-D282-4C5C-AA7D-FB36970D09D1@island-resort.com> <0B6C4756-6C69-4F66-9B5F-CD5B7A1CB9FA@wolfmcnally.com> <f70f44eb-111c-b1c7-00b5-c9e99af5e88a@gmail.com> <C6D174CC-4ECC-433F-AF16-4FBED1C644EB@wolfmcnally.com> <f5425e41-6cf8-16b7-0ba8-492c67e3d8b0@gmail.com> <8E24A9E2-8563-458E-88D8-C60423118824@wolfmcnally.com>
From: Anders Rundgren <anders.rundgren.net@gmail.com>
In-Reply-To: <8E24A9E2-8563-458E-88D8-C60423118824@wolfmcnally.com>
Content-Type: text/plain; charset="UTF-8"; format="flowed"
Content-Transfer-Encoding: 8bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/eLuwWlKr9tpkubYyRikAe-VWOJg>
Subject: Re: [Cbor] Implementing float->int numeric reduction
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 16 Aug 2023 07:00:25 -0000

On 2023-08-16 8:02, Wolf McNally wrote:
> Anders,
> 
>> On Aug 15, 2023, at 8:38 PM, Anders Rundgren <anders.rundgren.net@gmail.com> wrote:
>>
>> On the encoding level I don't find it logical or useful handling a probably rather small set of floating point data differently than the rest.
> 
> Am I correct that JCS, of which you are the first author, re-encodes “0.0” as “0”? By your own statement to do so is neither “logical” nor “useful”. So why did you bother? Why did you not just “let floats be floats”?

In this case the goal was to canonicalize IEEE 754 64-bit numbers. There could thus only be a single representation of a specific value.  To make it simple (...), we adopted the serialization method specified by ECMA.  Aided by a public algorithm and some 200 lines of rather intricate Open Source code (both well outside the team's competence), we got a solution.  That number serialization worked right out of the box for JavaScript gave us a head start.  However, this journey took 7 years!

Anyway, this is not directly translatable to CBOR, since CBOR is not built around a single "Number" type, uses binary encoding, and floating point support is even optional.  FWIW, I started my CBOR adventures early 2021 using https://cbor.me as a reference system.  My current encoding scheme is (probably) to 99.9% a copy of the reference.  My only "invention" is targeting the enterprise market with a "JSON killer" :)

Cheers,
Anders
reasonably good engineer, lousy salesman

> 
> https://datatracker.ietf.org/doc/html/rfc8785#name-serialization-of-numbers <https://datatracker.ietf.org/doc/html/rfc8785#name-serialization-of-numbers>
> 
> ~ Wolf
>