The Math.expm1()
method returns e (Euler's constant) raised to the given power minus 1. It is equivalent to ex - 1 in mathematics.
Example
// calculate e (Euler's constant)
// raised to the power of 2
// and then subtracted by 1
var value = Math.expm1(2);
console.log(value);
// Output : 6.38905609893065
expm1() Syntax
The syntax of the expm1()
method is:
Math.expm1(x)
Here, expm1()
is a static method. Hence, we need to access the method using the class name, Math
.
expm1() Parameters
The expm1()
method takes in:
- x - A number
expm1() Return Value
The expm1()
method returns:
- ex - 1 for argument x, where e is Euler's constant (2.71828).
NaN
for non-numeric arguments.
Example 1: JavaScript Math.expm1()
// calculate e raised to the power of 1 minus 1
var value1 = Math.expm1(1);
console.log(value1);
// calculate e raised to the power of 2 minus 1
var value2 = Math.expm1(2);
console.log(value2);
// calculate e raised to the power of 5 minus 1
var value3 = Math.expm1(5);
console.log(value3);
Output
1.718281828459045 6.38905609893065 147.4131591025766
In the above example,
Math.expm1(1)
- computes e1 - 1Math.expm1(2)
- computes e2 - 1Math.expm1(5)
- computes e5 - 1
Example 2: expm1() With 0
// calculate e raised to the power of 0 minus 1
var value = Math.expm1(0);
console.log(value);
// Output: 0
In the above example, we have used the expm1()
method to compute the e (Euler's constant) raised to the power of 0 and then subtracted by 1 i.e. e0 - 1.
The output 0
indicates the following mathematical result:
e0 - 1 = 0
Example 3: expm1() With Negative Numbers
// calculate e raised to the power of -1 minus 1
var value = Math.expm1(-1);
console.log(value);
// Output: -0.6321205588285577
In the above example, we have used the expm1()
method to compute the e (Euler's constant) raised to the power of -1 minus 1 i.e. e-1 - 1.
The output -0.6321205588285577
indicates that e-1 - 1 is a negative number. This is because e-1
is 0.36787944117144233, and subtracting 1 from it makes it negative.
Recommended Readings: