Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
expm1() function in PHP
The expm1() function returns e raised to the power x minus 1, which is mathematically represented as ex - 1. This function is particularly useful for calculating values close to zero with higher precision than using exp(x) - 1.
Syntax
expm1(number)
Parameters
number − A floating point value representing the exponent
Return Value
Returns a float representing ex - 1, where e is Euler's number (approximately 2.718281828).
Example 1
Basic usage of expm1() with different values −
<?php
echo "expm1(0) = " . expm1(0) . "<br>";
echo "expm1(1) = " . expm1(1) . "<br>";
echo "expm1(2) = " . expm1(2) . "<br>";
?>
expm1(0) = 0 expm1(1) = 1.718281828459 expm1(2) = 6.3890560989307
Example 2
Demonstrating the mathematical formula ex - 1 −
<?php
$val = 1.5;
echo "For x = " . $val . "<br>";
echo "expm1(" . $val . ") = " . expm1($val) . "<br>";
echo "exp(" . $val . ") - 1 = " . (exp($val) - 1) . "<br>";
?>
For x = 1.5 expm1(1.5) = 3.4816890703382 exp(1.5) - 1 = 3.4816890703382
Conclusion
The expm1() function provides an accurate way to calculate ex - 1, especially for small values of x where precision matters. It's equivalent to exp(x) - 1 but offers better numerical stability.
Advertisements
