JavaScript Math.expm1() Method



In JavaScript, the Math.expm1() method is used to calculate the value of e^x - 1, where "e" is the Euler's number (approximately 2.7183) and "x" is the argument passed to the function.

The mathematical formula for the Math.expm1() method is −

expm1(x)=e^x 1

Where,

  • e is Euler's number, the base of the natural logarithm (approximately 2.718).
  • x is the argument passed to the function.

Syntax

Following is the syntax of JavaScript Math.expm1() method −

Math.expm1(x)

Parameters

This method accepts only one parameter. The same is described below −

  • x: A number representing the exponent.

Return value

This method returns ex 1, where "e" is the base of the natural logarithms (approximately 2.718).

Example 1

In the following example, we are using the JavaScript Math.expm1() method to calculate the "e" raised to the power of 5, subtracted by 1 −

<html>
<body>
<script>
   const result = Math.expm1(5);
   document.write(result);
</script>
</body>
</html>

Output

If we execute the above program, it returns approximately 147.413 as result.

Example 2

When the argument is 0, the result is 0 because e0 - 1 is equal to 0 −

<html>
<body>
<script>
   const result = Math.expm1(0);
   document.write(result);
</script>
</body>
</html>

Output

As we can see the output, it returned 0 as result.

Example 3

The following example computes e(-1) - 1 −

<html>
<body>
<script>
   const result = Math.expm1(-1);
   document.write(result);
</script>
</body>
</html>

Output

The result will be approximately equal to -0.6321.

Example 4

Here, we are proving "-Infinity" and "Infinity" as arguments to this method −

<html>
<body>
<script>
   const result1 = Math.expm1(-Infinity);
   const result2 = Math.expm1(Infinity);
   document.write(result1, "<br>", result2);
</script>
</body>
</html>

Output

It returns "-1" and "Infinity" as result, respectively.