Public
Edited
Oct 24, 2023
Importers
11 stars
Insert cell
Insert cell
1 + 1e-14 - 1 // 🌶
Insert cell
d3.fsum([1, 1e-14, -1]) // 👍
Insert cell
d3.sum([1, -2e-17, -1]) // 🌶
Insert cell
d3.fsum([1, -2e-17, -1]) // 👍
Insert cell
Insert cell
Insert cell
d3.fsum([.1, NaN, undefined, .1, .1, .1, .1, .1, .1, .1, .1, .1])
Insert cell
d3.sum([.1, NaN, undefined, .1, .1, .1, .1, .1, .1, .1, .1, .1])
Insert cell
Insert cell
d3.fsum(new Set([{a: .1}, {a: .2}, {a: .3}, {a: .4}, {a: -1}]), d => d.a)
Insert cell
Insert cell
Insert cell
.1 + .1 + .1
Insert cell
d3.fsum([.1, .1, .1])
Insert cell
Insert cell
a = {
const a = new d3.Adder();
for (let i = 0; i < 3; i++) {
a.add(.01);
}
return a
}
Insert cell
a.valueOf()
Insert cell
+a // the + notation is a JavaScript shorthand notation for the valueOf method
Insert cell
Insert cell
Insert cell
test(d3.sum, 1000)
Insert cell
test(d3.fsum, 1000)
Insert cell
async function test(sum, delay) {
await Promises.delay(delay || 0)
const N = 10;

const t = performance.now();
for (let i = 0; i < N; i++) sum(M);
return (performance.now() - t) / N;
}
Insert cell
M = Float64Array.from({ length: 1e6 }, Math.random)
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