PHP expm1() Function

PHPServer Side ProgrammingProgramming

Definition and Usage

The expm1() function returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero, a case where 'exp (number) - 1' would be inaccurate due to subtraction of two numbers that are nearly equal.

expm1(x) = exp(x) - 1

This function returns a float value .

Syntax

expm1 ( float $arg ) : float

Parameters

Sr.NoParameter & Description
1arg
A floating point number whose expm1 is to be calculated.

Return Values

PHP expm1() function returns a floating point value.

PHP Version

This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.

Example

 Live Demo

Following example calculates expm1(2) and tallies the return value with (exp(2)-1) −

<?php
   echo "expm1(2) = " . expm1(2) . "\n";
   echo "exp(2)-1 = " . (exp(2)-1);
?>

Output

This will produce following result −

expm1(2) = 6.3890560989307
exp(2)-1 = 6.3890560989307

Example

 Live Demo

Following example returns value of expm1(0) −

<?php
   echo "expm1(0) = " . expm1(0) . "\n";
?>

Output

This will produce following result −

expm1(0) = 0

Example

 Live Demo

Let's check find out expm1(-1).−

<?php
   echo "expm1(-1) = " . expm1(-1) . "\n";
?>

Output

This will produce following result −

expm1(-1) = -0.63212055882856

Example

 Live Demo

Following example returns values of expm1(1) −

<?php
   echo "expm1(1) = " . expm1(1) . "\n";
?>

Output

This will produce following result −

expm1(1) = 1.718281828459
raja
Published on 29-Jun-2020 12:19:09
Advertisements