LOG1P(): log(1 + number)

<?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

Example 1: Calculating Compound Interest Using log1p()

<?php
$principal = 1000;
$rate = 0.05;
$time = 10;
$amount = $principal * exp($time * log1p($rate));
echo "Amount after 10 years: $amount";
?>

Example 2: Calculating Continuous Growth

<?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";
?>

Example 3: Calculating Natural Logarithm for Positive and Negative Numbers

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)
?>

Example 4: Use Case in Financial Calculations

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;
?>

Example 5: Comparing log() vs log1p()

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
?>

Math Functions LOG10() function LOG() function
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer