JSFiddle - React, Tailwind, and code Playground
by brigand
HTML
<pre id="out"></pre>
JavaScript
const items = [
0x3FF0000000000000n,
0x3FF0000000000001n,
0x3FF0000000000002n,
0x3FF000ff00000000n,
];
function asDouble(num) {
const array = new ArrayBuffer(64 / 8);
const uint8 = new Uint8Array(array);
for (let i = 0n; i < 8n; i += 1n) {
const byte = Number((num >> (i * 8n)) & 0xffn);
uint8[Number(i)] = byte;
}
const double = new Float64Array(array);
return double[0];
}
for (const item of items) {
out.textContent += asDouble(item);
out.textContent += '\n'
}
const mapped = items.map(asDouble)
out.textContent += mapped[0] === mapped[1]