Comment by sjrd

2 days ago

The spec mandates normalization of NaNs in ArrayBuffers. If other engines do not normalize, I believe it's a bug in those engines!

Chromium & Node (i.e. V8) do seem to just not normalize:

    arr = new Float64Array([0]);
    arr[0] = new Float64Array(new BigUint64Array([-123n]).buffer)[0];
    [...new Uint8Array(arr.buffer)] // [133, 255, 255, 255, 255, 255, 255, 255]

  • Running the following snippets:

        f = new Float64Array(1)
        dv = new DataView(f.buffer)
        dv.setBigInt64(0, -123n)
        console.log([...new Uint8Array(f.buffer)])
    
        f = new Float64Array(1)
        new BigUint64Array(f.buffer)[0] = -123n
        console.log([...new Uint8Array(f.buffer)])
    
        f = new Float64Array(1)
        f[0] = new Float64Array(new BigUint64Array([-123n]).buffer)[0]
        console.log([...new Uint8Array(f.buffer)])
    
        f = new Float64Array([NaN])
        console.log([...new Uint8Array(f.buffer)])
    

    I get on Chrome:

        [255, 255, 255, 255, 255, 255, 255, 133]
        [133, 255, 255, 255, 255, 255, 255, 255]
        [133, 255, 255, 255, 255, 255, 255, 255]
        [0, 0, 0, 0, 0, 0, 248, 127]
    

    And on Firefox:

        [ 255, 255, 255, 255, 255, 255, 255, 133 ]
        [ 133, 255, 255, 255, 255, 255, 255, 255 ]
        [ 0, 0, 0, 0, 0, 0, 248, 127 ]
        [ 0, 0, 0, 0, 0, 0, 248, 127 ]
    

    It looks like both implementations are buggy, Since both the DataView and buffer versions should be normalized.

    https://bugzilla.mozilla.org/show_bug.cgi?id=1393085