Closed Bug 1271646 Opened 9 years ago Closed 8 years ago

NaN value canonicalized inconsistently

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1140152

People

(Reporter: jugglinmike, Unassigned)

Details

Version: 3dc1902afe42afd9c94390d130995abe95480b05 (Thu May 5 17:45:58 2016 +0100) OS: Ubuntu Linux Architecture: x64 var myNaN = -NaN; var source = new Float32Array([myNaN]); var sliced = source.slice(); var sourceBytes = new Uint8Array(source.buffer); var slicedBytes = new Uint8Array(sliced.buffer); print(sourceBytes.join(' ')); print(slicedBytes.join(' ')); Expected: the same bit pattern, printed twice Actual: two distinct bit patterns 0 0 192 255 0 0 192 127 This behavior is observable using Float32Array and Float64Array. It seems to be limited to the `%TypedArray%.prototype.slice` method--the expected behavior occurs when Set (for example) is used instead, as in: subject[0] = myNaN; ES2015 24.1.1.6 SetValueInBuffer > If value is NaN, rawValue may be set to any implementation chosen IEEE > 754-2008 binary64 format Not-a-Number encoding. An implementation must always > choose the same encoding for each implementation distinguishable NaN value. http://www.ecma-international.org/ecma-262/6.0/#sec-setvalueinbuffer I discovered this while writing tests for Test262--SpiderMonkey is currently failing one of the following tests currently under review: https://github.com/tc39/test262/pull/623
I don't think this is a bug. slice() is required to canonicalize because it performs a sequence of GetValueFromBuffer and SetValueInBuffer; the former method *must* canonicalize. But SetValueInBuffer is not required to canonicalize - it can just store the bit pattern (the wording is "may"). So source.buffer contains -NaN because the value was not canonicalized and sliced.buffer contains NaN, the canonical representation.
See step 15 of https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.slice . If the type of the source and destination are the same, implementations are required to copy byte-by-byte, rather than through Get/Set.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.