Published unlisted
Edited
Nov 7, 2019
Insert cell
Insert cell
a = 2**52
Insert cell
[-4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5].map((x) => (x + a) - a)
Insert cell
[0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0].map((x) => (x + a) - a)
Insert cell
[-4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5].map((x) => (x - a) + a)
Insert cell
[-4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5].map(Math.round)
Insert cell
[-4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5].map(round)
Insert cell
[-4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5].map(round2)
Insert cell
round = (x) => {
const b = a * ((x > 0) - (x < 0)); // a * sgn(x)
return (x + b) - b; }
Insert cell
round2 = (x) => copysign((abs(x) + a) - a, x);
Insert cell
copysign = {
const arr = new Float64Array(2);
const intarr = new Int32Array(arr.buffer);
const SMASK = 0x80000000; // 1000 0000 0000 0000 0000 0000 0000 0000
return (x, s) => {
arr[0] = x;
arr[1] = s;
intarr[1] = intarr[1] - (intarr[1] & SMASK) + (intarr[3] & SMASK);
return arr[0];
}
}
Insert cell
abs = {
const arr = new Float64Array(1);
const intarr = new Int32Array(arr.buffer);
const SMASK = 0x80000000; // 1000 0000 0000 0000 0000 0000 0000 0000
return (x) => {
arr[0] = x;
intarr[1] = intarr[1] - (intarr[1] & SMASK);
return arr[0];
}
}
Insert cell
c = 2 * (2**1023 - 2**970)
Insert cell
(c + a) - a
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more