JavaScript Math.expm1() 方法
在 JavaScript 中,Math.expm1() 方法用于计算 e^x - 1 的值,其中"e"是欧拉常数(约为 2.7183),"x"是传递给函数的参数。
Math.expm1() 方法的数学公式为 −
expm1(x)=e^x 1
其中,
- e 是欧拉常数,即自然对数的底数(约为 2.718)。
- x 是传递给函数的参数。
语法
以下是JavaScript Math.expm1() 方法的语法 -
Math.expm1(x)
参数
此方法仅接受一个参数。具体说明如下 -
- x:表示指数的数字。
返回值
此方法返回 ex 1,其中"e"是自然对数的底数(约为 2.718)。
示例 1
在下面的示例中,我们使用 JavaScript Math.expm1() 方法计算"e"的 5 次方减 1 -
<html> <body> <script> const result = Math.expm1(5); document.write(result); </script> </body> </html>
输出
执行上述程序,结果约为 147.413。
示例 2
当参数为 0 时,结果为 0,因为 e0 - 1 等于 0 −
<html> <body> <script> const result = Math.expm1(0); document.write(result); </script> </body> </html>
输出
正如我们在输出中看到的,它返回了 0。
示例 3
以下示例计算 e(-1) - 1 −
<html> <body> <script> const result = Math.expm1(-1); document.write(result); </script> </body> </html>
输出
结果约等于 -0.6321。
示例 4
这里,我们证明"-Infinity"和"Infinity"作为此方法的参数 -
<html> <body> <script> const result1 = Math.expm1(-Infinity); const result2 = Math.expm1(Infinity); document.write(result1, "<br>", result2); </script> </body> </html>
输出
分别返回"-1"和"Infinity"作为结果。

