Thoughts on IEEE P754

Sam Ruby rubys at intertwingly.net
Fri Aug 22 04:22:45 PDT 2008


On Fri, Aug 22, 2008 at 2:30 AM, Jason Orendorff
<jason.orendorff at gmail.com> wrote:
> On Thu, Aug 21, 2008 at 9:08 PM, Sam Ruby <rubys at intertwingly.net> wrote:
>> Waldemar Horwat wrote:
>>> - We should not print the trailing zeroes.  IEEE P754 does not
>>> require it, and it breaks things such as array lookup.  There is
>>> precedence for this in ECMAScript:  -0 and +0 both print as "0".  If
>>> someone really wants to distinguish among equal numbers, he can do it
>>> with a function call to one of the mandated functions.
>>
>> Please explain the breakage?
>
> In ES3, an expression like a[b] calculates ToObject(a) and
> ToString(b), then performs the property lookup. Thus arr[0] and
> arr["0"] are identical in meaning.
>
>  http://bclary.com/2004/11/07/#a-11.2.1
>
> Assuming we retain this rule and add decimal numbers, a question
> arises as to how this code should behave:
>
>  var a = [];
>  a[0] = "first";
>  a[0.0m] = "second";   // a second property?
>  a[0.000m] = "third";   // a third?
>
> The question applies to all objects, not just Arrays.
>
> I think this is a tricky question; neither answer is obviously right to me.

Understood.  And I understand that Waldemar would prefer that trailing
zeros be dropped.

It seems to me that if trailing zeros are retained in a call to
ToString, then to be consistent with ES3, the three assignments above
would produce three properties.  And if trailing zeros are lost, you
would expect to only have one.  Both approaches are internally
consistent, and it surprises me to see either one characterized as
"breaking" array lookup.

Like Mike, I would argue that toString on decimal quantities preserve
trailing zeros.

> -j

- Sam Ruby


More information about the Es-discuss mailing list