Re: [Json] "best practices" Vs. Profile for i-json

Stephen Dolan <stephen.dolan@cl.cam.ac.uk> Mon, 04 August 2014 12:29 UTC

Return-Path: <stedolan@stedolan.net>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id AE1741B2AAE for <json@ietfa.amsl.com>; Mon, 4 Aug 2014 05:29:07 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: 1.877
X-Spam-Level: *
X-Spam-Status: No, score=1.877 tagged_above=-999 required=5 tests=[BAYES_05=-0.5, FM_FORGED_GMAIL=0.622, FRT_ADOBE2=2.455, RCVD_IN_DNSWL_LOW=-0.7] autolearn=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 dlIgt8vaVfIh for <json@ietfa.amsl.com>; Mon, 4 Aug 2014 05:29:05 -0700 (PDT)
Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com [209.85.217.176]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 8B5841B2AAC for <json@ietf.org>; Mon, 4 Aug 2014 05:29:05 -0700 (PDT)
Received: by mail-lb0-f176.google.com with SMTP id u10so5199074lbd.7 for <json@ietf.org>; Mon, 04 Aug 2014 05:29:03 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=l025kmbm0KxRiwQRiyGyD6GgmhSUgvYgy+or/OBKGsk=; b=MRVhlka3kV8FNucsKA2wAfvKhlvebDdeCgAv3UjHDBRBD9FgJ1T9sebZO5fHvJWIc/ 6MdT7jcYQ+lU+O21Ax0Un+eoEfE8Ud5k/Pn8mxC1bT4UwPinFxf9WtBOWmVUKbGJrECF ccBF56CCEngvljhxwTU/pcmMFWgp+2q6AGptZVQJibBZ2tedXB/3j+AAv7z/VbWLAT+w IuVf8KnYxwzmPZpCsnOsjN0egem3g0zcKr+ssCjmofM0dxPP/hGTEEThsjg6AWB5nKPz 8e6JL5CA6t136AZ7hmSewpoCve2R1jFe4mMX7tT2e+mhpmIeNuZyBDBUtK8As+Tj8Ib5 yQ2g==
X-Gm-Message-State: ALoCoQlVyIIFCPCwMkLwomTXgwa9yVOwXy1Bo3xqQEQuveaaDDtiJqA++3mfBwvakMbsohetBRhM
MIME-Version: 1.0
X-Received: by 10.112.235.42 with SMTP id uj10mr2476335lbc.80.1407155343274; Mon, 04 Aug 2014 05:29:03 -0700 (PDT)
Sender: stedolan@stedolan.net
Received: by 10.114.22.42 with HTTP; Mon, 4 Aug 2014 05:29:03 -0700 (PDT)
X-Originating-IP: [131.111.184.26]
In-Reply-To: <2d53157574f749e0b1399b9e39564ecd@BL2PR02MB307.namprd02.prod.outlook.com>
References: <2d53157574f749e0b1399b9e39564ecd@BL2PR02MB307.namprd02.prod.outlook.com>
Date: Mon, 04 Aug 2014 13:29:03 +0100
X-Google-Sender-Auth: ql-pTToi2TSDyEVR_TlFj7MnvpE
Message-ID: <CA+mHimPoZzmoio0Y+JgUDHd4b9B4yPm9fc3a1SCV6tayJ_9z7A@mail.gmail.com>
From: Stephen Dolan <stephen.dolan@cl.cam.ac.uk>
To: Larry Masinter <masinter@adobe.com>
Content-Type: text/plain; charset="UTF-8"
Archived-At: http://mailarchive.ietf.org/arch/msg/json/gls6hyGqXumeyupTRJkkRW4iDSU
Cc: IETF JSON WG <json@ietf.org>
Subject: Re: [Json] "best practices" Vs. Profile for i-json
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.15
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: Mon, 04 Aug 2014 12:29:07 -0000

On Fri, Aug 1, 2014 at 10:55 PM, Larry Masinter <masinter@adobe.com> wrote:
> "All numeric values in I-JSON MUST round-trip to IEEE floating point and back to the same string."

The exact requirement is more subtle than this.

The number 1.1 cannot be represented exactly as an IEEE754 double. The
closest number which can is:

A = 1.100000000000000088817841970012523233890533447265625

The requirements that most languages make of their double conversion
functions (at least, those that bother to specify such things) are:

(1) parsing a string returns the IEEE754 double which is closer to the
decimal number than any other IEEE754 double (with rules for breaking
ties, and rules for strings representing numbers outside [-DBL_MAX,
DBL_MAX])

(2) printing a double returns some string whose decimal value is
closer to the provided IEEE754 double than to any other IEEE754 double
(with similar exceptions for ties, nan, inf, etc.)

Some languages (e.g. Java) go further and require that printing return
the shortest string compatible with (2). Without this condition, there
are many different strings that validly correspond to A above: "1.1"
(the shortest), "1.10", "1.10000000000000009". In general,
print(parse(str)) need not be equal to str, but
parse(print(parse(str))) must be equal to parse(str).

The point of this is that being a valid string representation of an
IEEE754 number has nothing to do with round-tripping to the same
string, and is not a property of the string itself. Instead, the
condition that specifies "use doubles with json" has to do with when
JSON values are considered equivalent.

Two JSON documents differing only in whitespace outside strings are
(MUST be? SHOULD be?) considered equivalent by any implementation. If
you want to specify "use doubles" you should state something similar,
like:

"An implementation [MUST NOT/SHOULD NOT] distinguish between two
numeric literals whose decimal values round to the same IEEE754
double-precision value (using standard round-to-nearest, ties-to-even
rounding)."

Stephen