Re: [Json] Minus Zero

Anders Rundgren <anders.rundgren.net@gmail.com> Wed, 22 June 2016 15:49 UTC

Return-Path: <anders.rundgren.net@gmail.com>
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 5CBEC12D95A for <json@ietfa.amsl.com>; Wed, 22 Jun 2016 08:49:25 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.7
X-Spam-Level:
X-Spam-Status: No, score=-2.7 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-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 ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id emN4HFuQVRNX for <json@ietfa.amsl.com>; Wed, 22 Jun 2016 08:49:23 -0700 (PDT)
Received: from mail-wm0-x22e.google.com (mail-wm0-x22e.google.com [IPv6:2a00:1450:400c:c09::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id C8CC412DA4E for <json@ietf.org>; Wed, 22 Jun 2016 08:37:51 -0700 (PDT)
Received: by mail-wm0-x22e.google.com with SMTP id a66so11696466wme.0 for <json@ietf.org>; Wed, 22 Jun 2016 08:37:51 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=UL+IeliQo2/SgxxU+avlZqt3EdsM110sMoYLj8ski7Y=; b=dANWZgkGt+cWRLLa8O4PbM6uQj4ygNDC4C7GSg0AtyqzGIlxa3nAZkrOqMl6dPeZMG nDxT+T7pJPg9SEeoRGcMlQls1xXQ6jLubLjpno3ZEvdvmEaxjRGW3EDUoI/olNj7xd6E GreGaQdD90E84STyBN2xECozJ2RDwtKty4fyl/zBrf4FyHHrz2lAAtZeHemwtrdp/Ynd oNFdY5OWqmsaZuaeyKcdM3QiZHYETxZldys8qP21OWX9/Wz0danLlO1c1oQUWXWaXaak QC4vpjSyo+LC8sFKeYM+zBw2x48gghJhnshg0pzMM7RFeaoIuP8SuKON9KboKTkh8Ve+ PD6A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=UL+IeliQo2/SgxxU+avlZqt3EdsM110sMoYLj8ski7Y=; b=cbXJntF2FXEBnet6iTmrs0gCR1vlw9HIANLr9C0qR3t+I43R9XfbBeMe1gRdiDwesO CF0TOAQEK7794AF5DXr/lRiASw9WWoAqoHYrrX/tOGrXZBlrI8Z3S0sIi3yMRP71n5e9 0PfjmisZ8G0MksIqSisN9t9sjMrFyzrafjop5Fm5qMuqafGycjVBXb8lH/axx2cK/txL PEAJbBGNnCCqjAtJ7+rIo5g21OB8RP6HYVzpQ2zplLE9voDIqzIkrE4YOXsiyt9b+Bn6 MwkQnxtnINtHDWuaD0txwFveO3OylphHEMlOoFyH/J+lsCOpT/OWZgo8h58c/o3EESYa 31Xw==
X-Gm-Message-State: ALyK8tKbelt/S2Sf8ll5WXlMaUIuH4PEfc/fv5eL66+8ZupCq1Q2jJb01I0z9YwFdERnLA==
X-Received: by 10.194.81.166 with SMTP id b6mr27142575wjy.81.1466609870351; Wed, 22 Jun 2016 08:37:50 -0700 (PDT)
Received: from [172.28.0.180] ([46.218.0.106]) by smtp.googlemail.com with ESMTPSA id a4sm51887653wjq.40.2016.06.22.08.37.49 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Jun 2016 08:37:49 -0700 (PDT)
To: John Cowan <cowan@mercury.ccil.org>
References: <2a7f88b9-f719-dfd8-08a9-1777833e53d8@gmail.com> <e94f3bd0-1635-b2e1-c5da-9ae350ae652d@gmail.com> <57684982.2010705@tzi.org> <8e5dc4b2-a897-30e7-6e37-921c463275cd@gmail.com> <CADEL5zv-0ZRdcXKp1R=EBHqcJquOR7CYR=EW75xmtFpXG5OLOg@mail.gmail.com> <20160621154243.GG13605@mercury.ccil.org> <6d834be1-14c3-d8b4-09dd-2a992cfe55a6@gmail.com> <20160621204150.GJ13605@mercury.ccil.org>
From: Anders Rundgren <anders.rundgren.net@gmail.com>
Message-ID: <afb35b0e-c346-7f34-4c2c-072f12c39b42@gmail.com>
Date: Wed, 22 Jun 2016 17:37:43 +0200
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1
MIME-Version: 1.0
In-Reply-To: <20160621204150.GJ13605@mercury.ccil.org>
Content-Type: text/plain; charset="windows-1252"; format="flowed"
Content-Transfer-Encoding: 7bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/json/lm78VShwXgS5-8AilhzJZq5W9hI>
Cc: Carsten Bormann <cabo@tzi.org>, Christian Zangl <coralllama@gmail.com>, JSON WG <json@ietf.org>
Subject: Re: [Json] Minus Zero
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.17
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: Wed, 22 Jun 2016 15:49:25 -0000

On 2016-06-21 22:41, John Cowan wrote:
> Anders Rundgren scripsit:
>
>> Apparently the ES6 folks consider IEEE 0.0 and -0.0 equal during JSON
>> serialization.
>
> In effect that means that -0, like NaN and Infinity and -Infinity, can't
> be serialized correctly as JSON.  But instead of being serialized as null,
> it's serialized the same as 0.

I would have done the same.  -0.0 is as I understand as close to zero you can get.
The need for separating the -0.0 and 0.0 in real-world applications is probably 0.0 :-)

If full IEEE notation is needed "string" representation seems to be the only way ahead.

>> In order to make anything else JSON would need separate integer and
>> floating point types.
>
> I don't understand that.  JavaScript's internal model of numbers already
> includes -0.0 (e.g. the value of the expression 1/(-1*0) is -Infinity).
> The node.js and Chrome REPLs will print -0 in appropriate circumstances
> (whereas the Rhino and Edge REPLs will not).

I just referred to the fact that -0 is not a useful way of serializing an integer,
it only makes (some) sense in an IEEE floating point world.

By using a single type for holding "Number", the designers had to do some compromises.

In my java-based JSON parser I have added additional checks so that if you expect an
integer using a getInt() access method, "19.0" would generate an exception.  Serializing
integers above abs((2**53)-1) also generates an exception.

Anders