Re: [Json] -0.0

Bjoern Hoehrmann <derhoermi@gmx.net> Fri, 27 September 2013 14:38 UTC

Return-Path: <derhoermi@gmx.net>
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 4CCCD21F9E00 for <json@ietfa.amsl.com>; Fri, 27 Sep 2013 07:38:18 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.292
X-Spam-Level:
X-Spam-Status: No, score=-2.292 tagged_above=-999 required=5 tests=[AWL=0.307, BAYES_00=-2.599]
Received: from mail.ietf.org ([12.22.58.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GUxfGaN+OYum for <json@ietfa.amsl.com>; Fri, 27 Sep 2013 07:38:13 -0700 (PDT)
Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by ietfa.amsl.com (Postfix) with ESMTP id 5E16821E808A for <json@ietf.org>; Fri, 27 Sep 2013 07:38:06 -0700 (PDT)
Received: from netb.Speedport_W_700V ([91.35.17.151]) by mail.gmx.com (mrgmx101) with ESMTPA (Nemesis) id 0LoaCE-1W5kl40arq-00gUHR for <json@ietf.org>; Fri, 27 Sep 2013 16:38:05 +0200
From: Bjoern Hoehrmann <derhoermi@gmx.net>
To: R S <sayrer@gmail.com>
Date: Fri, 27 Sep 2013 16:38:03 +0200
Message-ID: <795b4997e5opmtdjil1vivhi40nbh0n63d@hive.bjoern.hoehrmann.de>
References: <BF7E36B9C495A6468E8EC573603ED9411EF1BB0B@xmb-aln-x11.cisco.com> <CAChr6SyznBktmOLpT-EiZ5Nm_0jZ16M0tOo4aZ_jhSDb=HHDqg@mail.gmail.com> <6D5CFCAD-5B75-4246-BE42-D42E4D35C344@vpnc.org> <CAChr6SzEBdgF_Cv2ZnC1Oo2CnL06dwZqsOKA=HTVkgArcTyLEw@mail.gmail.com>
In-Reply-To: <CAChr6SzEBdgF_Cv2ZnC1Oo2CnL06dwZqsOKA=HTVkgArcTyLEw@mail.gmail.com>
X-Mailer: Forte Agent 3.3/32.846
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Provags-ID: V03:K0:7vWgFIGuggdx2gTU46SR/q3XxNhERoBA3JZp4CnKWKjqFUkQ6Xs rjL+E2D4TSf19rnOg3IfWEXnheemb/rrt+0zCTMIXNJiM/dr97SkHbXm9U5zi8kanAEettO Z1IcNLc8NRQTJVuGGZaY3ifFNdLwQ97VSGJJIvy3HVIW3vabP0sEsxkoT131xISQl6swNaK nx5LW3Z/jCnjmvDXnHyRQ==
Cc: JSON WG <json@ietf.org>
Subject: Re: [Json] -0.0
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.12
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: <http://www.ietf.org/mail-archive/web/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: Fri, 27 Sep 2013 14:38:18 -0000

* R S wrote:
>On Thu, Sep 26, 2013 at 11:41 AM, Paul Hoffman <paul.hoffman@vpnc.org>wrote:
>
>>    Numbers which represent zero without a sign, for example as 0 or 0.0
>>    not -0 or -0.0, are interoperable in the sense that software
>>    implementations will agree on the zero value.  Signed zeros are
>>    significant in some numerically-intensive applications, but
>>    implementations which read JSON texts cannot be relied upon to
>>    preserve that distinction.
>>
>> On Sep 26, 2013, at 10:31 AM, R S <sayrer@gmail.com> wrote:
>>
>> > I don't think there is a rationale for the text on -0.0. Is it for
>> non-IEE754 implementations?
>>
>> Do we need to state a rationale here, or does the text stand on its own?
>>
>>
>I meant that I don't see why it's in the draft at all. I propose deleting
>this paragraph, since I don't believe it is correct. Most implementations
>can be relied upon to preserve signed zeros.

The primary problem with negative zero is that it is very common for
number-to-string algorithms to render `-0` as `0`, and accordingly it
is common that negative zero vanishes accidentally, say when you have

  process_json_string(json_string)

and turn that into

  process_json_string(sanatise(json_string))

where sanatise parses, modifies, and re-serialises the json_string.
As I have mentioned, ecmascript's JSON.stringify is an example of a
JSON serialisation function that does not preserve negative zero.

The secondary problem is that many deployed implementations treat a
value like `-0` as integer value and do not preserve the sign. As an
example,

  % perl -MJSON -e "printf '%g', JSON->new->decode('[-0]')->[0]"
  0

Also in case of Perl, `-0` is not the same as `-0.0`,

  % perl -MJSON -e "printf '%g', JSON->new->decode('[-0.0]')->[0]"
  -0
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/