Thoughts on IEEE P754

Sam Ruby rubys at intertwingly.net
Fri Aug 22 07:51:11 PDT 2008


Jason Orendorff wrote:
> On Fri, Aug 22, 2008 at 6:22 AM, Sam Ruby <rubys at intertwingly.net> wrote:
>> On Fri, Aug 22, 2008 at 2:30 AM, Jason Orendorff
>> <jason.orendorff at gmail.com> wrote:
>>>  var a = [];
>>>  a[0] = "first";
>>>  a[0.0m] = "second";   // a second property?
>>>  a[0.000m] = "third";   // a third?
>> [...]
>>
>> 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.
> 
> Well, the intuition is that two equal numbers should index the same
> property.  This is an invariant in ES3 and it makes a lot of sense.

Correct me if I'm wrong, but the intuition would more properly be based 
on string equality, and not numeric equality.  As an example, how many 
properties would the following produce, with an conformant 
implementation of ES3?

var a = [];
a['0.0'] = "first";
a[0.0] = "second";  // a second property
a['0'] = "third";   // replaces *second* property


Intuition is a very tricky thing.  Place the following in front of any 
third grader, and tell me what they will write below the line.


    1 . 0 5
  + 2 . 0 5
  _________




- Sam Ruby




More information about the Es-discuss mailing list