w3docs logo
  1. Snippets
  2. PHP
  3. How to Use the expm1() Function in PHP

How to Use the expm1() Function in PHP

Here, we will have a look at an inbuilt PHP function known as expm1() that is applied for calculating e raised to the power of a particular argument minus 1. First of all, let’s see the syntax, used for this function:

float expm1($power)

It is capable of taking a single parameter $power specifying the power e should be raised to. This function is capable of returning a floating point value that is the value of a raised to the $power of the specific argument -1. So, (e$power-1) will be returned by it.

For a better perception of the function, take a look at the example below:

<?php
// PHP program to demonstrate the expm1() function
$n1 = 1;
$n2 = 0;
//prints value of e^1 - 1
echo "e^", $n1, "-1 = ", expm1($n1), "\n";
//prints value of e^0 - 1
echo "e^", $n2, "-1 = ", expm1($n2), "\n";
?>

The output will be as follows:

e^1-1 = 1.718281828459
e^0-1 = 0

Now, let’s see another example where the expm1() function is demonstrated by using an array:

<?php
// PHP code to illustrate the working
// of expm1() Function
// input array
$array = array(2, 3, 1, 5);
// print all the e^x-1 value in the arrays
foreach ($array as $i) echo 'e^' . $i . '-1 = ' . expm1($i) . "\n";
?>

After running this code you will ha the following output:

e^2-1 = 6.3890560989307
e^3-1 = 19.085536923188
e^1-1 = 1.718281828459
e^5-1 = 147.41315910258

For more information and examples of using the expm1() function, you can refer to this page.

Do you find this helpful?