v147 · javascript · covered on mdn
Math.sumPrecise
A static method that sums an iterable of numbers and returns the exact mathematical sum rounded once to the nearest double, avoiding the floating-point precision loss that accumulates when adding values in a naive loop. TC39 Stage 4 (ECMAScript 2026).
this feature is documented on MDN
MDN: Math.sumPrecise()
MDN has a full reference page including the algorithm details, examples comparing results to a naive loop sum, browser compatibility, and the TC39 proposal link. gendn doesn't duplicate that here.
quick reference
| Signature | Math.sumPrecise(iterable) |
|---|---|
| Returns | number — the precisely computed sum |
| Typical use | Financial totals, physics simulations, statistical aggregates where error accumulation matters |
| Shipped in | Chrome 147 (desktop + Android) |
| Standard | ECMAScript 2026 (TC39 Stage 4) |
| ChromeStatus | 4790090146643968 — Math.sumPrecise |
| TC39 proposal | tc39 / proposal-math-sum |
Syntax
Signature from ECMA-262 §21.3.2.34 Math.sumPrecise ( items ) (fetched 2026-11-22):
Math.sumPrecise(items)
Parameters
items— an iterable (array,Set, generator, typed array…) whose values are all Numbers. Values are not coerced: strings, BigInts,nulland objects are rejected.
Return value
- A Number: the exact real-number sum of all values, rounded once. Special values follow the spec’s state machine: any
NaN, or both+Infinityand-Infinity, givesNaN; otherwise an infinity gives that infinity. - An empty iterable, or one containing only
-0, returns-0(not+0, unlike areduce((a, b) => a + b, 0)loop).
Exceptions
TypeError—itemsisnull/undefinedor not iterable, or any yielded value is not a Number (the iterator is closed first).RangeError— more than 253 − 1 values; the spec notes this is not expected to be reached in practice.
Examples
Math.sumPrecise.Source: chrome-platform-showcase — math-sumpreciseNaive sum vs. precise sum
const values = [1e20, 0.1, -1e20];
values.reduce((a, b) => a + b, 0); // 0 — the 0.1 is lost
Math.sumPrecise(values); // 0.1
// exact sum of the two doubles, rounded once:
Math.sumPrecise([0.1, 0.2]); // 0.30000000000000004
Math.sumPrecise([]); // -0
Feature detection with a fallback
const sum = typeof Math.sumPrecise === "function"
? (xs) => Math.sumPrecise(xs)
: (xs) => { let s = 0; for (const x of xs) s += x; return s; }; // less precise fallback
try {
Math.sumPrecise([1, "2"]);
} catch (e) {
console.log(e instanceof TypeError); // true — no coercion of "2"
}
Source: ECMA-262 §Math.sumPrecise; live float-drift-lab demo.
Browser compatibility
| Browser | Version | Notes |
|---|---|---|
| Chrome | 147 | Standard track, not experimental, not deprecated |
| Chrome Android | 147 | BCD mirror of Chrome |
| Edge | 147 | BCD mirror of Chrome |
| Firefox | 137 | Firefox for Android: mirror (137) |
| Safari | 26.2 | Safari on iOS: mirror (26.2) |
Specifications
| Specification | Section |
|---|---|
| ECMAScript Language Specification (ECMA-262) | § Math.sumPrecise ( items ) |