Re: [Json] Minus Zero

Carsten Bormann <cabo@tzi.org> Sun, 19 June 2016 21:09 UTC

Return-Path: <cabo@tzi.org>
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 0358112D81E for <json@ietfa.amsl.com>; Sun, 19 Jun 2016 14:09:17 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.6
X-Spam-Level:
X-Spam-Status: No, score=-2.6 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham autolearn_force=no
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 xsNcUP5oKmKz for <json@ietfa.amsl.com>; Sun, 19 Jun 2016 14:09:15 -0700 (PDT)
Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:c:538::196]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 18ED012D81F for <json@ietf.org>; Sun, 19 Jun 2016 14:09:15 -0700 (PDT)
Received: from mfilter20-d.gandi.net (mfilter20-d.gandi.net [217.70.178.148]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 2E52B1720AF; Sun, 19 Jun 2016 23:09:13 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at mfilter20-d.gandi.net
Received: from relay4-d.mail.gandi.net ([IPv6:::ffff:217.70.183.196]) by mfilter20-d.gandi.net (mfilter20-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id QPG0usl9leOe; Sun, 19 Jun 2016 23:09:11 +0200 (CEST)
X-Originating-IP: 93.199.242.26
Received: from nar-3.local (p5DC7F21A.dip0.t-ipconnect.de [93.199.242.26]) (Authenticated sender: cabo@cabo.im) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 00E0E17209F; Sun, 19 Jun 2016 23:09:10 +0200 (CEST)
Message-ID: <576709F5.9080000@tzi.org>
Date: Sun, 19 Jun 2016 23:09:09 +0200
From: Carsten Bormann <cabo@tzi.org>
User-Agent: Postbox 4.0.8 (Macintosh/20151105)
MIME-Version: 1.0
To: Christian Zangl <coralllama@gmail.com>
References: <2a7f88b9-f719-dfd8-08a9-1777833e53d8@gmail.com>
In-Reply-To: <2a7f88b9-f719-dfd8-08a9-1777833e53d8@gmail.com>
X-Enigmail-Version: 1.2.3
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/json/wkTXXerbgzlkhVCBP_ADLeZIDa4>
Cc: "json@ietf.org" <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: Sun, 19 Jun 2016 21:09:17 -0000

Christian Zangl wrote:
> The RFC does not mention this but most (all?) JavaScript JSON libraries
> stringify -0 as "0" (including
> https://github.com/douglascrockford/JSON-js).

Which RFC?

-0 evaluates to 0 in most programming languages (two's complement
integer arithmetic).
-0.0 of course is something different (floating point arithmetic
distinguishes positive and negative zero).
I would expect a decent JSON implementation to serialize this number as
"-0.0" for maximum interoperability with recipients that internalize
integer numbers as integers.

The JSON interchange format does not call out the difference between
integers and floating point numbers, because it only deals in the
decimal representations of numbers, but many programming languages do.

JavaScript doesn't have that distinction in its number system, but the
quirks following from that fact are less relevant for the JSON standard
than for its JavaScript-constrained profile I-JSON, RFC 7493.
That RFC is indeed missing mention of this particular quirk in its
section 2.2, where that information might possibly help.

Grüße, Carsten

>> JSON.dump([0])
=> "[0]"
>> JSON.dump([-0])
=> "[0]"
>> JSON.dump([0.0])
=> "[0.0]"
>> JSON.dump([-0.0])
=> "[-0.0]"

>> JSON.load("[-0.0]")
=> [-0.0]
>> JSON.load("[0.0]")
=> [0.0]
>> JSON.load("[0]")
=> [0]
>> JSON.load("[-0]")
=> [0]