ES Decimal status

Maciej Stachowiak mjs at apple.com
Wed Sep 24 08:53:26 PDT 2008


On Sep 24, 2008, at 8:28 AM, Sam Ruby wrote:

>>>
>>> My apologies.  That wasn't the question I was intending.
>>>
>>> Can you identify code that today depends on numeric binary 64  
>>> floating
>>> point which makes use of operations such as unrounded division and
>>> depends on trailing zeros being truncated to compute array indexes?
>>>
>>> I would think that such code would be more affected by factors  
>>> such as
>>> the increased precision and the fact that 1.2-1.1 produces
>>> 0.09999999999999987 than on the presence or absence of any trailing
>>> zeros.

I don't see how the result of 1.2 - 1.1 would affect array indexing.  
Fractional values are not used as array indices.

>>> But given the continued use of words such as "broken" and  
>>> "unusable",
>>> I'm wondering if I'm missing something obvious.

In ECMAScript all property names are nominally strings. The generic  
property access syntax is also used for array indexing. The official  
spec-level explanation of this is that the subscript inside the square  
brackets is converted toString, and then looked up as any normal  
string-named property. In practice implementations optimize the  
storage of and access to such properties so there is no actual  
conversion between integers and strings going on.

Given this, it seems pretty clear to me that the sanity of ECMAScript  
array indexing depends on the fact that a number equal to an integer  
will stringify as that integer.

In other languages, array indexing converts to integer rather than  
nominally to string, so this issue does not arise.

I decline to accept the burden of proof on this; those who wish to  
alter the behavior of ECMAScript array indexing should be the ones  
presenting research on existing code. Though I will grant that the  
burden of proof here is smaller than for truly compatibility-breaking  
changes, since existing code will not be directly affected.

I would think it is pretty likely there is code out there that does  
things like multiply by 0.5 (faster than dividing by 2, right?) and  
use the result as an array index. But maybe you can show otherwise.

Regards,
Maciej



More information about the Es-discuss mailing list