JavaScript (ES2026) reference · Math Methods and Constants

JavaScript Math.sumPrecise() Method

Add up an iterable of numbers with full precision, avoiding the rounding errors of repeated + additions.

JavaScript (ES2026) Since ES2026

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Math.sumPrecise(items)

Parameters

ParameterDescription
items An iterable of numbers.

Return value

A number.

Examples

Precise vs naive sumTry it yourself
const values = [0.1, 0.2, 0.3];
console.log(values.reduce((a, b) => a + b, 0), Math.sumPrecise(values));

Output

0.6000000000000001 0.6
Large and small numbersTry it yourself
console.log(Math.sumPrecise([1e20, 1, -1e20]), 1e20 + 1 - 1e20);

Output

1 0

Math.sumPrecise() is new in ES2026 and not yet available in every engine (Node.js 26, for example, doesn't have it), so the outputs above are the results defined by the specification. Check support before relying on it, or fall back to reduce():

const sum = (xs) => (Math.sumPrecise ? Math.sumPrecise(xs) : xs.reduce((a, b) => a + b, 0));

Version history

VersionChange
JavaScript ES2026Added

In other languages

Was this page helpful?