Math.log1p()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

概述

Math.log1p() 函数返回一个数字加 1 后的自然对数 (底为 E), 既log(x+1).

语法

js
Math.log1p(x)

参数

x

任意数字。

描述

如果参数的值小于 -1,则返回 NaN

函数 y = log(x+1) 的图形是这样的:

log(x+1)

示例

js
Math.log1p(Math.E - 1); // 1
Math.log1p(0); // 0
Math.log1p("0"); // 0
Math.log1p(-1); // -Infinity
Math.log1p(-2); // NaN
Math.log1p("foo"); // NaN

规范

Specification
ECMAScript® 2025 Language Specification
# sec-math.log1p

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
log1p

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见