The java.lang.StrictMath.log1p() is an in-built method in Java which is used to accept a double value as argument and returns the natural logarithm of the sum of the argument and 1.
public static double log1p(double x)
Parameters: The function accepts a double value x as parameter and calculates the natural algorithm of (1+x).
Return Values: This method returns the value ln(1+x). The result of log1p(x) is almost as close as the actual result of ln(1 + x) for small values x than the floating-point evaluation of log(1.0+x).
Following cases are considered :
- The function returns positive infinity if the argument is positive infinity.
- The function returns negative infinity for negative infinty.
- The function returns NaN if the argument is NaN or less than -1.
- The function returns zero with the sign same as that of the argument if the argument is zero.
Input : 2018.0 Output : 7.610357618312838 Input : -4743.0 Output : NaN
Below programs illustrate the working of java.lang.StrictMath.log1p() function:
Program 1: In this program, finite and non-zero argument is passed.
Natural Logarithm of 2019.00567 is 7.610360426629845 Natural Logarithm of 100000.0 is 11.512925464970229
Program 2: In this program, infinite and negative arguments are passed.
Natural Logarithm of Infinity is Infinity Natural Logarithm of -4742.0 is NaN
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.