<?Php
echo LOG1P(6);// Output is 1.9459101490553
echo "<br>";
echo LOG1P(-0.3);// Output is -0.35667494393873
echo "<br>";
echo LOG1P(0.4);// Output is 0.33647223662121
echo "<br>";
echo LOG1P(1.2);// Output is 0.78845736036427
?>
Syntax
LOG1P(X);
X is the input number . We get output as LOG of 1+X
<?php
$principal = 1000;
$rate = 0.05;
$time = 10;
$amount = $principal * exp($time * log1p($rate));
echo "Amount after 10 years: $amount";
?>
<?php
$growth_rate = 0.03; // 3% growth
$time = 7; // over 7 years
$growth = exp(log1p($growth_rate) * $time);
echo "Total growth factor over 7 years: $growth";
?>
The log1p() function calculates the natural logarithm of 1 plus the given input. It’s particularly useful for numbers close to zero to avoid precision loss. Here's an example:
<?php
echo log1p(0.5); // Logarithm of 1.5
echo "<br>";
echo log1p(-0.3); // Logarithm of 0.7 (works for negative numbers too)
?>
log1p() can be used in compound interest calculations where precise computations of log values for small numbers matter:
<?php
$rate = 0.05; // 5% interest
$time = 10; // Time in years
$amount = log1p($rate * $time);
echo "Logarithmic value: " . $amount;
?>
Comparing results for numbers close to zero:
<?php
echo log(1 + 1e-15); // Traditional log
echo "<br>";
echo log1p(1e-15); // log1p() provides better precision
?>