FW: FW: Values for numeric literals

Allen Wirfs-Brock Allen.Wirfs-Brock at microsoft.com
Fri Jun 19 11:46:01 PDT 2009

(forwarding back to the list with Mike’s permission)

From: Mike Cowlishaw [mailto:MFC at uk.ibm.com]
Sent: Friday, June 19, 2009 9:11 AM
To: Allen Wirfs-Brock
Cc: cam at mcc.id.au
Subject: Re: FW: Values for numeric literals

Hi Allen,

This is of course one of the many reasons I have been campaigning for languages to use decimal, where such conversions can be exact.  :-)

In the case of literals in ECMAScript, the literal is a decimal number (each digit has 10x the value of the one to its right), and this has to be converted to a binary number (each digit has 2x the value of the one to its right).  This conversion cannot usually be exact (because binary floating-point numbers cannot exactly represent decimal fractions because they do not have a power of 5 available) and it is actually quite expensive to do a 'correctly rounded' conversion.    Therefore IEEE 754-1985 allowed such conversions to be correct to within one ulp (unit in last place) rather than correctly rounded (correct to with 0.5 ulp, roughly).

ECMAScript edition 3 probably allows two rules for literals because two different implementations worked differently for very long literals and one or both quoted that rule as justification.  Why they worked differently probably boils down to a lazy/hurried programmer somewhere back in the mid-1990s...

IEEE 754-2008 requires all such conversions to be correctly rounded.  ES 3.1 should probably adopt that, too.

For more information see the first few Qs in the FAQ at:  http://speleotrove.com/decimal/decifaq.html

Hope that helps!


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Mike Cowlishaw, IBM Fellow
IBM UK (MP8), PO Box 31, Birmingham Road, Warwick, CV34 5JL

Allen Wirfs-Brock <Allen.Wirfs-Brock at microsoft.com>

19/06/2009 16:03


Mike Cowlishaw/UK/IBM at IBMGB


"cam at mcc.id.au" <cam at mcc.id.au>


FW: Values for numeric literals

Do you have any insight into the history and rationale relating to the issue below?


-----Original Message-----
From: es5-discuss-bounces at mozilla.org [mailto:es5-discuss-bounces at mozilla.org] On Behalf Of Cameron McCormack
Sent: Thursday, June 18, 2009 11:24 PM
To: es5-discuss at mozilla.org
Subject: Values for numeric literals


I sent a mail a while ago asking about the rounding specified for the
mathematical value of a NumericLiteral.


I didn’t get a reply, so I thought I might ping the list again.

My reading of 7.8.3 (in the ES5 draft spec as well as ES3) is that
numeric literals with a certain number of significant digits can result
in two possible Number values.  With this statement:

 x = 1.23451234512345123457

the 7 should be the 21st significant digit, so the Number value assigned
to x can be either 1.2345123451234512345 or 1.2345123451234512346.  Is
that correct?  Why give a choice about what number value is used?  What
about with hex numeric literals?  Also, “incrementing the literal at the
20th significant digit position” doesn’t sound precise enough.

Why have this rounding method for NumericLiterals that is different from
the rounding method used in the definition of “the number value of x” in
section 8.5?

For the curious, I ask this because I’m wondering whether I should be
doing something like the rounding in ES5 7.8.3 in Web IDL, where I
define what the value of a float terminal is:




Cameron McCormack ≝ http://mcc.id.au/
es5-discuss mailing list
es5-discuss at mozilla.org


Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es5-discuss/attachments/20090619/51df2b9d/attachment-0001.html>

More information about the es5-discuss mailing list