Example 1 — Read Number.EPSILON
Print the constant and confirm it equals 2−52.
Number.EPSILON;
Number.EPSILON === 2 ** -52; // true How It Works
The engine exposes the IEEE-754 unit in the last place at 1.0 as a named constant.
Number.EPSILON is a static data property on Number (same API as MDN Number.EPSILON). It is the difference between 1 and the next greater representable Number — about 2.22e-16. This tutorial covers its value, float equality, when not to use a bare EPSILON, five examples, and try-it labs.
Static property
2−52
Gap after 1
Near-1 equality
No
Everywhere
JavaScript numbers use IEEE-754 double precision. Only finitely many values fit in 64 bits, so many decimals — including 0.1 — are approximations. That is why 0.1 + 0.2 === 0.3 is false.
Number.EPSILON names the spacing between 1 and the next Number. Near magnitude 1, that spacing is a common starting tolerance for “close enough” equality checks.
Static properties belong to Number itself. Always write Number.EPSILON. There is no (1).EPSILON, and you do not call it like a function.
This page is part of JavaScript Number Properties. Related tools include Number.isNaN() and Number.isFinite() for validating numeric results.
EPSILON PropertyDouble precision stores a 52-bit fraction (mantissa). At magnitude 1, the least significant bit is worth 2−52 — that is Number.EPSILON.
Number.MIN_VALUE (the tiniest positive Number).General form of the static property Number.EPSILON:
Number.EPSILON 2−52, approximately 2.220446049250313e-16.
| Attribute | Value |
|---|---|
| Writable | false |
| Enumerable | false |
| Configurable | false |
Number.EPSILON; // ≈ 2.220446049250313e-16
Number.EPSILON === 2 ** -52; // true
Math.abs(0.2 - 0.3 + 0.1) < Number.EPSILON; // true
function equal(x, y, tolerance = Number.EPSILON) {
return Math.abs(x - y) < tolerance;
} | Goal | Code |
|---|---|
| Read machine epsilon | Number.EPSILON |
| Confirm 2−52 | Number.EPSILON === 2 ** -52 |
| Near-1 equality | Math.abs(x - y) < Number.EPSILON |
| Scaled tolerance | Math.abs(x - y) < Math.abs(x) * Number.EPSILON |
| Data-step tolerance | Math.abs(x - y) < 0.01 (example) |
| Strict equality | === (avoid for most floats) |
Four facts to remember about Number.EPSILON.
staticProperty on Number
2**-52≈ 2.22e-16
~1Arithmetic near magnitude 1
noRead-only constant
=== vs Number.EPSILON vs scaled tolerance| Case | === | Bare EPSILON | Scaled / custom |
|---|---|---|---|
0.1 + 0.2 vs 0.3 | false | true (near 1) | true |
1000.1 + 1000.2 vs 2000.3 | false | false (too strict) | true with 2000 * EPSILON |
Form steps of 0.1 | Often false | Too strict | Use e.g. 0.01 |
Examples follow MDN Number.EPSILON patterns. Use View Output or Try It Yourself for each case.
Read the constant and see MDN’s tiny-error demo.
Number.EPSILONPrint the constant and confirm it equals 2−52.
Number.EPSILON;
Number.EPSILON === 2 ** -52; // true The engine exposes the IEEE-754 unit in the last place at 1.0 as a named constant.
A classic cancellation leaves a residual smaller than EPSILON.
const result = Math.abs(0.2 - 0.3 + 0.1);
result; // 2.7755575615628914e-17
result < Number.EPSILON; // true The absolute residual is smaller than the gap at 1, so it counts as “numerically zero” for near-1 work.
Equality helpers and magnitude caveats from MDN.
Treat two values as equal when their difference is below EPSILON.
function equal(x, y) {
return Math.abs(x - y) < Number.EPSILON;
}
equal(0.1 + 0.2, 0.3); // true
0.1 + 0.2 === 0.3; // false Strict equality fails because of binary rounding. A small absolute tolerance succeeds when values are near 1.
Around 2000, rounding error can exceed EPSILON.
function equal(x, y) {
return Math.abs(x - y) < Number.EPSILON;
}
const x = 1000.1;
const y = 1000.2;
const z = 2000.3;
x + y; // 2000.3000000000002
equal(x + y, z); // false Absolute accuracy shrinks as the exponent grows. Do not use a bare EPSILON for all sizes.
Pass a larger tolerance when the magnitude is large.
function equal(x, y, tolerance = Number.EPSILON) {
return Math.abs(x - y) < tolerance;
}
const x = 1000.1;
const y = 1000.2;
const z = 2000.3;
equal(x + y, z, 2000 * Number.EPSILON); // true MDN-style fix: scale EPSILON by the magnitude of the data. Match tolerance to both size and input precision.
===.0.1 often need a much larger tolerance.EPSILONMath.abs(x - y) measures how far apart the values are.
Near 1: EPSILON. Larger data: scale it. User data: match step size.
If the difference is smaller than the tolerance, treat as equal.
Approximate equality — not bitwise identity.
Number.EPSILON only.Number.EPSILON() — it is not a function.Number.MIN_VALUE is a different concept (smallest positive Number).Number.EPSILON is Baseline Widely available — part of ES2015 and supported in every modern browser and Node.js.
Safe for production everywhere. Use it as a named machine epsilon near magnitude 1.
Bottom line: Use Number.EPSILON for near-1 float equality. Scale or replace the tolerance for larger magnitudes and coarser input precision.
Number.EPSILON is the static constant for the gap after 1 in IEEE-754 doubles — a practical starting point for approximate equality when values sit near magnitude 1.
Continue with more Number properties, validate results with isFinite(), or browse Number methods.
Number.EPSILON on the constructor(1).EPSILON or Number.EPSILON()=== for most floating-point checksNumber.MIN_VALUENumber.EPSILONStatic machine epsilon for floating-point closeness near 1.
static
API2**-52
Constantnear 1
Usetolerance
Patternwhen large
CaveatMachine epsilon is a classic numerical-analysis idea. In JavaScript it is exposed as Number.EPSILON, equal to 2 ** -52 — the unit in the last place at 1.0 for IEEE-754 binary64 numbers.
Return to the hub for static Number constants.
8 people found this page helpful