Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Number.EPSILON: spacing between numbers near 1

Number.EPSILON is the difference between 1 and the smallest representable Number greater than 1, equal to 2^-52.

Version: ECMAScript 2015 onward; example target: Node.js 24.22.2

Syntax

Number.EPSILON

Number.EPSILON has the exact value 2 ** -52, approximately 2.220446049250313e-16: it is the difference between 1 and the smallest representable Number greater than 1. The immediate gap below 1 is 2 ** -53, so epsilon is not symmetric spacing around 1. It helps express tolerance for rounding error, such as when 0.1 + 0.2 is not exactly equal to 0.3; it is not the smallest positive Number, which is Number.MIN_VALUE.

Spacing between representable numbers grows with the exponent, so Math.abs(a - b) < Number.EPSILON alone is not a universal comparison. For similarly scaled values, epsilon can be multiplied by Math.max(1, Math.abs(a), Math.abs(b)) and a safety factor; measurements or financial rules need a tolerance derived from their domain. Very small values may require a separately chosen absolute threshold.

The property has existed since ECMAScript 2015 and is non-writable, non-enumerable, and non-configurable. The example defines a scaled nearlyEqual test that accepts the usual 0.1 + 0.2 error, then checks the constant’s exact value and descriptor. Assignment cannot change Number.EPSILON and can throw TypeError in strict code.

Examples

const nearlyEqual = (a, b, factor = 4) =>
  Math.abs(a - b) <= Number.EPSILON * factor * Math.max(1, Math.abs(a), Math.abs(b));

const total = 0.1 + 0.2;
console.log(total === 0.3, nearlyEqual(total, 0.3));
console.log(Number.EPSILON === 2 ** -52);
const descriptor = Object.getOwnPropertyDescriptor(Number, "EPSILON");
console.log(descriptor.writable, descriptor.enumerable, descriptor.configurable);

Result

false true
true
false false false

Number.EPSILON → scaled comparison, exact 2^-52, and a non-writable descriptor

Sources