PHP Function Reference

PHP log1p() Function



The PHP log1p() function returns the natural logarithm of (1 + number), i.e., log(1+number). In special cases it returns the following:

  • If the argument is NAN or less than -1, then the result is NAN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative one, then the result is negative infinity.

Syntax

log1p(number)

Parameters

number Required. Specify the number.

Return Value

Returns the natural logarithm of (1 + number), i.e., log(1+number).

Example:

In the example below, log1p() function is used to calculate the log(1+number).

<?php
echo "log1p(-1) = ".log1p(-1)."\n";
echo "log1p(0) = ".log1p(0)."\n";
echo "log1p(0.5) = ".log1p(0.5)."\n";
echo "log1p(1) = ".log1p(1)."\n";
echo "log1p(10) = ".log1p(10)."\n";
echo "log1p(100) = ".log1p(100)."\n";
echo "log1p(INF) = ".log1p(INF)."\n";
echo "log1p(-INF) = ".log1p(-INF)."\n";
echo "log1p(NAN) = ".log1p(NAN)."\n";
?>

The output of the above code will be:

log1p(-1) = -INF
log1p(0) = 0
log1p(0.5) = 0.40546510810816
log1p(1) = 0.69314718055995
log1p(10) = 2.3978952727984
log1p(100) = 4.6151205168413
log1p(INF) = INF
log1p(-INF) = NAN
log1p(NAN) = NAN

❮ PHP Math Reference