API reference

Number, Math & BigInt

36/36Coverage30/36Strict (zero caveats)

Number, Math, and the two global parse helpers, backed by IEEE-754 doubles with an exact-i64 fast path where the inputs are integers. The remaining divergence is narrow: the trig/log/hyperbolic family comes from the platform libm, which can differ from V8's fdlibm in the last binary digit. Everything else — toFixed/toPrecision/toExponential and every toString radix, exponent formatting (min-digit, `e+5`), the constants, parseFloat's `"0x10"` → `0` hex-prefix rule, parseInt's hex auto-detect, and the bit ops — matches real JS.

Exact Works, with caveats Not supported

Number.isInteger(x)

Exact
Number.isInteger(x: number): boolean

Reports whether x is a finite integer value — floor(x) == x gated on a finiteness check, so ±Infinity and NaN are false, matching real JS.

Number.isFinite(x)

Exact
Number.isFinite(x: number): boolean

True when x is a finite number (not NaN, not ±Infinity). Unlike the global isFinite, does not coerce non-number arguments.

Number.isNaN(x)

Exact
Number.isNaN(x: number): boolean

True only when x is the NaN value itself — the non-coercing sibling of the global isNaN.

Number.isSafeInteger(x)

Exact
Number.isSafeInteger(x: number): boolean

True when x is an integer that round-trips exactly through a double — i.e. within ±(2^53 − 1).

Number.parseInt(s)

Exact
Number.parseInt(s: string, radix?: number): number

Parses a leading integer out of s. Returns a double (as real JS), so a no-digits input is a real NaN via an endptr-checked strtoll. With radix omitted, auto-detects base 16 for a "0x"/"0X" prefix and base 10 otherwise (no octal auto-detect).

Number.parseFloat(s)

supported
Number.parseFloat(s: string): number

Parses a leading floating-point number out of s. A "0x10" hex prefix reads only its leading 0 → 0 (real parseFloat, unlike Number("0x10") → 16). A no-conversion input returns a real NaN via the endptr check. Only the exact word "Infinity" parses to Infinity ("inf" is NaN).

Number.MAX_SAFE_INTEGER

Exact
Number.MAX_SAFE_INTEGER: number

The largest integer that round-trips through a double, 2^53 − 1 (9007199254740991).

Number.MIN_SAFE_INTEGER

Exact
Number.MIN_SAFE_INTEGER: number

The most-negative safe integer, −(2^53 − 1).

Number.EPSILON

Exact
Number.EPSILON: number

The difference between 1 and the smallest double greater than 1, 2^-52.

Number.MAX_VALUE

Exact
Number.MAX_VALUE: number

The largest representable positive double, roughly 1.7976931348623157e+308.

Number.MIN_VALUE

Exact
Number.MIN_VALUE: number

The smallest representable positive (subnormal) double, roughly 5e-324.

Number.POSITIVE_INFINITY

Exact
Number.POSITIVE_INFINITY: number

The +Infinity value.

Number.NEGATIVE_INFINITY

Exact
Number.NEGATIVE_INFINITY: number

The −Infinity value.

Number.NaN

Exact
Number.NaN: number

The NaN value, as a Number static property.

Number.prototype.toFixed(n)

Exact
(x: number).toFixed(digits?: number): string

Formats x with a fixed number of digits after the decimal point, by the spec's algorithm over the exact value: an exact tie rounds to the larger value ((2.5).toFixed(0) is "3"), |x| ≥ 1e21 gives String(x), and a digit count outside 0..100 throws a RangeError. The digits argument is optional and defaults to 0.

Number.prototype.toString(radix?)

Exact
(x: number).toString(radix?: number): string

Renders x as a string. The default (and radix 10) is exactly String(x) — the shortest round-trip decimal; any other base runs V8's own algorithm, the fraction to the double's precision, matching Node digit for digit. A radix outside 2..36 throws a RangeError.

Number.prototype.toPrecision(n)

Exact
(x: number).toPrecision(precision?: number): string

Formats x to the given number of significant digits by the spec's algorithm: exact rounding with ties to the larger value, exponential notation below 1e-6 or at 10^precision and up, and a RangeError outside 1..100. With the precision omitted, toPrecision() is exactly String(x).

Number.prototype.toExponential(n?)

Exact
(x: number).toExponential(fractionDigits?: number): string

Formats x in exponential notation by the spec's algorithm over the exact value (ties to the larger value, e+4 minimum-digit exponents); with no argument, the shortest round-trip mantissa (12345 → 1.2345e+4), as in Node.

parseInt(s, radix?) (global)

Exact
parseInt(s: string, radix?: number): number

The global parseInt — same runtime as Number.parseInt. A no-digits input yields a real NaN; with radix omitted, hex auto-detect for a "0x" prefix, base 10 otherwise.

parseFloat(s) (global)

supported
parseFloat(s: string): number

The global parseFloat — same runtime as Number.parseFloat, including the "0x10" → 0 hex-prefix rule. A no-conversion input yields a real NaN; only the exact word "Infinity" parses to Infinity.

isNaN(x) (global)

Exact
isNaN(x: number): boolean

The global isNaN — true when x is NaN.

isFinite(x) (global)

Exact
isFinite(x: number): boolean

The global isFinite — true when x is finite.

Math.floor/ceil/round/trunc

Exact
Math.floor(x); Math.ceil(x); Math.round(x); Math.trunc(x)

The four rounding modes. A float input stays a double end-to-end, so NaN/±Infinity pass through unchanged; Math.round uses JS's tie-toward-+Infinity (Math.round(-4.5) === -4), including the -0 result for Math.round(-0.5). An integer input keeps the exact-i64 path.

console.log(Math.floor(-3.2))  // -4
console.log(Math.ceil(3.2))    // 4
console.log(Math.round(3.5))   // 4
console.log(Math.trunc(-3.9))  // -3
See it in a full example →

Math.abs

Exact
Math.abs(x: number): number

Absolute value, preserving the integer fast path for integer inputs.

console.log(Math.abs(-10))   // 10
See it in a full example →

Math.sqrt/pow/hypot

Exact
Math.sqrt(x); Math.pow(x, y); Math.hypot(...xs)

Square root, exponentiation, and the Euclidean-norm helper.

console.log(Math.pow(2.0, 10.0))   // 1024
console.log(Math.sqrt(9.0))         // 3
console.log(Math.hypot(3.0, 4.0))  // 5
See it in a full example →

Math.log/log2/log10

Works, with caveats
Math.log(x); Math.log2(x); Math.log10(x)

Natural, base-2, and base-10 logarithms.

console.log(Math.floor(Math.log2(8.0)))     // 3
console.log(Math.floor(Math.log10(1000.0))) // 3
See it in a full example →

Math.sin/cos/tan

Works, with caveats
Math.sin(x); Math.cos(x); Math.tan(x)

The primary trigonometric functions (radians).

const sinHalf = Math.sin(Math.PI / 2.0)
console.log(Math.round(sinHalf))   // 1
See it in a full example →

Math.min/max

Exact
Math.min(...xs: number[]): number; Math.max(...xs: number[]): number

Any float argument promotes the fold to llvm.minimum/llvm.maximum — NaN propagates and -0.0 orders below +0.0, as the JS spec; all-integer calls stay exact i64.

console.log(Math.min(1, 5, 3))  // 1
console.log(Math.max(1, 5, 3))  // 5
See it in a full example →

Math.sign

Exact
Math.sign(x: number): number

The float path returns ±1.0 or the input itself (NaN stays NaN, a signed zero keeps its sign); the integer path stays exact i64.

console.log(Math.sign(42))   // 1
console.log(Math.sign(-7))   // -1
console.log(Math.sign(0))    // 0
See it in a full example →

Math.random()

Exact
Math.random(): number

Returns a float in [0, 1).

const roll = Math.floor(Math.random() * 6.0)
const rollOk = roll >= 0 && roll < 6
console.log(rollOk)  // 1
See it in a full example →

Math.PI/E/LN2/LN10/SQRT2/LOG2E/LOG10E

Exact
Math.PI; Math.E; Math.LN2; Math.LN10; Math.SQRT2; Math.LOG2E; Math.LOG10E

The standard Math constants.

console.log(Math.PI)     // 3.141592653589793
console.log(Math.E)      // 2.718281828459045
console.log(Math.SQRT2)  // 1.4142135623730951
See it in a full example →

Math.cbrt/expm1/log1p

Works, with caveats
Math.cbrt(x); Math.expm1(x); Math.log1p(x)

cbrt uses a deterministic, correctly-rounded fdlibm implementation (@__kml_cbrt) rather than platform libm, whose runtime cbrt is not reliably correctly-rounded and diverged by OS (glibc cbrt(27) gave 3.0000000000000004); expm1/log1p delegate to libm.

console.log(Math.cbrt(27.0))   // 3
console.log(Math.expm1(0.0))   // 0
console.log(Math.log1p(0.0))   // 0
See it in a full example →

Math.asin/acos/atan/atan2

Works, with caveats
Math.asin(x); Math.acos(x); Math.atan(x); Math.atan2(y, x)

The inverse trigonometric functions.

console.log(Math.acos(1.0))                     // 0
console.log(Math.round(Math.atan2(1.0, 1.0) * 4.0))  // 3
See it in a full example →

Math.sinh/cosh/tanh

Works, with caveats
Math.sinh(x); Math.cosh(x); Math.tanh(x)

The hyperbolic functions.

console.log(Math.sinh(0.0))   // 0
console.log(Math.cosh(0.0))   // 1
console.log(Math.tanh(0.0))   // 0
See it in a full example →

Math.exp and Math.asinh/acosh/atanh

Works, with caveats
Math.exp(x); Math.asinh(x); Math.acosh(x); Math.atanh(x)

The exponential function and the inverse hyperbolic functions.

console.log(Math.exp(0))     // 1
console.log(Math.acosh(1))   // 0
console.log(Math.atanh(0))   // 0
See it in a full example →

Math.clz32/fround/imul

Exact
Math.clz32(x); Math.fround(x); Math.imul(a, b)

clz32 via LLVM's own llvm.ctlz.i32 intrinsic; fround via an fptrunc/fpext float32 round-trip; imul via 32-bit mul + sign-extend, giving real 32-bit-wraparound integer multiplication distinct from plain *'s double-precision result.

console.log(Math.clz32(1))     // 31
console.log(Math.imul(3, 4))   // 12
console.log(Math.fround(5.5))  // 5.5
See it in a full example →