Math.exp()

Math.exp() 静态方法返回 e 的数字幂。那是

¥The Math.exp() static method returns e raised to the power of a number. That is

𝙼𝚊𝚝𝚑.𝚎𝚡𝚙 ( 𝚡 ) = e x \mathtt{\operatorname{Math.exp}(x)} = \mathrm{e}^x

Try it

语法

¥Syntax

js
Math.exp(x)

参数

¥Parameters

x

一个号码。

返回值

¥Return value

代表 ex 的非负数,其中 e 为 自然对数的底

¥A nonnegative number representing ex, where e is the base of the natural logarithm.

描述

¥Description

因为 exp()Math 的静态方法,所以你始终将其用作 Math.exp(),而不是用作你创建的 Math 对象的方法(Math 不是构造函数)。

¥Because exp() is a static method of Math, you always use it as Math.exp(), rather than as a method of a Math object you created (Math is not a constructor).

请注意,非常接近 0 的数的 e 次方将非常接近 1,并且会导致精度损失。在这种情况下,你可能想改用 Math.expm1,并获得精度更高的答案小数部分。

¥Beware that e to the power of a number very close to 0 will be very close to 1 and suffer from loss of precision. In this case, you may want to use Math.expm1 instead, and obtain a much higher-precision fractional part of the answer.

示例

¥Examples

使用 Math.exp()

¥Using Math.exp()

js
Math.exp(-Infinity); // 0
Math.exp(-1); // 0.36787944117144233
Math.exp(0); // 1
Math.exp(1); // 2.718281828459045
Math.exp(Infinity); // Infinity

规范

Specification
ECMAScript Language Specification
# sec-math.exp

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看