JavaScript Math.log1p() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

Math.log1p(x) returns the natural logarithm of 1 + x. It is more accurate than Math.log(1 + x) when x is very close to zero.

Math is built into JavaScript. Call the method directly. It is not a constructor, so never write new Math().

Syntax

Call Math.log1p() like this. Start with this line.

JavaScript
Math.log1p(x)
CallWhat it does
Math.log1p(x)Returns the natural logarithm of 1 + x.

Built into JavaScript. Call Math.log1p() on the Math object — no import required.

Library declarations
JavaScript
Math.log1p(x)
JavaScript
interface Math {
  log1p(x: number): number;
}

Parameters

ParameterDescription
xRequired. A number greater than or equal to -1. -1 returns -Infinity. Less than -1 returns NaN.

Return Value

Return ValueDescription
numberThe natural logarithm of 1 + x. Returns -Infinity for -1, and NaN for numbers below -1.

JavaScript Examples

Example 1 — Basic Use

The result is the natural log of 1 + x.

JavaScript
console.log(Math.log1p(0));     // 0
console.log(Math.log1p(1));     // 0.6931471805599453
console.log(Math.log1p(-1));    // -Infinity
console.log(Math.log1p(-2));    // NaN
Try It Yourself

How It Works

  1. Zero. log(1 + 0) is log(1), which is 0.
  2. One. log(2) is about 0.6931.
  3. Minus one. log(0) is -Infinity.
  4. Below -1. log of a negative number is NaN.

Example 2 — Precision for Tiny Numbers

See how Math.log(1 + x) loses digits for a tiny x.

JavaScript
var tiny = 1e-15;

console.log(Math.log(1 + tiny));  // 1.110223024625156e-15
console.log(Math.log1p(tiny));    // 9.999999999999995e-16
Try It Yourself

How It Works

  1. Tiny x. 1e-15 is a very small number.
  2. Rounded away. 1 + tiny cannot keep all digits, so Math.log gets a slightly wrong input.
  3. log1p is accurate. Math.log1p(tiny) returns almost exactly 1e-15.

Example 3 — Simple Return to Continuous Return

Finance uses log returns. Convert a 5% simple return and back.

JavaScript
var simple = 0.05;  // 5%

var continuous = Math.log1p(simple);
console.log(continuous);                  // 0.04879016416943201
console.log(Math.expm1(continuous));      // 0.05
Try It Yourself

How It Works

  1. Simple return. A gain of 5% is 0.05.
  2. Convert. Math.log1p(0.05) is the continuous (log) return, about 0.0488.
  3. Convert back. Math.expm1() gives back the original 0.05.

Browser & Runtime Support

Math.log1p() is part of ES2015 and is Baseline Widely available in modern browsers and Node.js.

✓ Baseline · ES2015

Math.log1p()

Supported in Chrome, Firefox, Safari, Edge, and Node.js for years. Safe for modern apps without a polyfill.

98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Math.log1p Excellent

Bottom line: Use Math.log1p() in new code. Only very old browsers, like Internet Explorer, lack it.

Frequently Asked Questions

Math.log1p(x) returns the natural log of 1 + x. The name means "log of 1 plus". Math.log1p(0) is 0.
For very small x, 1 + x loses precision. Math.log1p(x) keeps the correct digits.
It returns -Infinity, because it calculates the log of 0. Anything below -1 returns NaN.
Math.expm1(). Math.expm1(Math.log1p(x)) gives back x.
It was added in ES2015 and works in all modern browsers and Node.js.

Next: log2()

Learn how to find the base-2 logarithm.

log2() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful