Hacker News new | past | comments | ask | show | jobs | submit login

This doesn't work on Firefox, as it normalizes NaNs as they're extracted from ArrayBuffers. Presumably because SpiderMonkey uses NaN-boxing itself, and thus just doesn't have any way to represent actual non-canonical NaN floats.





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


Dammit Mozilla, first no WebGPU, now this?! /s



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: