Re: [Json] [jose] EcmaScript V6 - numbers

Carsten Bormann <cabo@tzi.org> Mon, 02 November 2015 03:30 UTC

Return-Path: <cabo@tzi.org>
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 87E961B32DD; Sun, 1 Nov 2015 19:30:22 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.55
X-Spam-Level:
X-Spam-Status: No, score=-1.55 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, HELO_EQ_DE=0.35] 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 yu0QOw6K09pO; Sun, 1 Nov 2015 19:30:20 -0800 (PST)
Received: from mailhost.informatik.uni-bremen.de (mailhost.informatik.uni-bremen.de [IPv6:2001:638:708:30c9::12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 2552E1B32DC; Sun, 1 Nov 2015 19:30:19 -0800 (PST)
X-Virus-Scanned: amavisd-new at informatik.uni-bremen.de
Received: from submithost.informatik.uni-bremen.de (submithost.informatik.uni-bremen.de [IPv6:2001:638:708:30c9::b]) by mailhost.informatik.uni-bremen.de (8.14.5/8.14.5) with ESMTP id tA23UEPe012254; Mon, 2 Nov 2015 04:30:14 +0100 (CET)
Received: from dhcp-38-127.meeting.ietf94.jp (t20010c4000003032cc8f9d73cbb98481.v6.meeting.ietf94.jp [IPv6:2001:c40:0:3032:cc8f:9d73:cbb9:8481]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by submithost.informatik.uni-bremen.de (Postfix) with ESMTPSA id 3nq09x1R34z2Fj7; Mon, 2 Nov 2015 04:30:12 +0100 (CET)
Message-ID: <5636D8BC.1020107@tzi.org>
Date: Mon, 02 Nov 2015 12:30:04 +0900
From: Carsten Bormann <cabo@tzi.org>
User-Agent: Postbox 4.0.7 (Macintosh/20151021)
MIME-Version: 1.0
To: "Manger, James" <James.H.Manger@team.telstra.com>
References: <255B9BB34FB7D647A506DC292726F6E13BB16C9857@WSMSG3153V.srv.dir.telstra.com>
In-Reply-To: <255B9BB34FB7D647A506DC292726F6E13BB16C9857@WSMSG3153V.srv.dir.telstra.com>
X-Enigmail-Version: 1.2.3
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Archived-At: <http://mailarchive.ietf.org/arch/msg/json/RHxoMv04KLBKXO23dWhethe0-ew>
Cc: "json@ietf.org" <json@ietf.org>, "jose@ietf.org" <jose@ietf.org>, Anders Rundgren <anders.rundgren.net@gmail.com>
Subject: Re: [Json] [jose] EcmaScript V6 - numbers
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: <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: Mon, 02 Nov 2015 03:30:22 -0000

Here's mine (converting from C library %g format to JS toString format):

class Float
  def cbor_diagnostic           # do a little bit of JSON.stringify
gaming (ECMA-262-2015, 7.1.12.1)
    a = abs
    if a < 1 && a >= 1e-6
      inspect.sub(/(\d)[.](\d+)e-(\d+)/) {"0.#{"0" * ($3.to_i -
1)}#{$1}#{$2}"}
    else
      inspect.sub(/(e[+-])0+/) {$1}
    end
  end
end

Apart from selecting the shortest representation, you need to select
details of the exponent format etc.  But the biggest problem with number
c14n in JSON is that the last digit may not be uniquely determined
(i.e., there are a number of shortest-form decimal numbers that map to
the same binary64).

Grüße, Carsten