Interactive Lab

Precision Arithmetic & Collection Insertion in ES2026

Explore Math.sumPrecise and Map getOrInsert with TypeScript 6.

precision-math.ts
// ES2026: Precise sum & Map.prototype.getOrInsert
const transactions = [0.1, 0.2, 0.3];
const total = Math.sumPrecise(transactions);

const categoryLedger = new Map<string, number[]>();
categoryLedger
  .getOrInsert('finances', () => [])
  .push(total);

Key Mechanics

  • Math.sumPrecise(): Native IEEE-754 accurate floating-point summation.
  • Map.prototype.getOrInsert(): Atomic retrieval or lazy initialization for map values.
Summation Runtime
Standard Sum

0.6000000000000001

Math.sumPrecise()

0.6