Comment by vhcr
6 months ago
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.
No comments yet
Contribute on Hacker News ↗