Home >>PHP Math Functions >PHP log1p() Function

PHP log1p() Function

PHP log1p() Function

PHP log1p() function is used to calculate log(1+number) of the given input value as $number argument, computed in such a way that is accurate even when the value of given number is close to zero. It accepts only a single parameter $number.

Syntax:

  log1p($number);

Parameter Values

Parameter Description
number This is a required parameter. This parameter defines the number to process.

Here is an example of log1p() function in PHP:

<html>
<body>

<?php

echo log1p(0)."<br>";
echo log1p(1)."<br>";
echo log1p(5)."<br>";
echo log1p(10)."<br>";
echo log1p(100)."<br>";


?>

</body>
</html>
Output:
0
0.69314718055995
1.7917594692281
2.3978952727984
4.6151205168413

Here is another example of log1p() function in PHP:

<html>
<body>

<?php

echo log(1)."<br>";
echo log1p(1)."<br>";
echo log(10)."<br>";
echo log(11)."<br>";
echo log1p(10)."<br>";  // log(10+1)
echo log(100)."<br>";
echo log(101)."<br>";   
echo log1p(100)."<br>";  // log(100+1)


?>

</body>
</html>
Output:
0
0.69314718055995
2.302585092994
2.3978952727984
2.3978952727984
4.6051701859881
4.6151205168413
4.6151205168413