log1p(): This method is available in the Math class of Java.
Syntax:
double java.lang.Math.log1p(double x)
This method takes one argument of type double as its parameter. This method returns the natural logarithm of the sum of the argument and 1 (i.e ln(x+1)).
Note: For small values x, the result of log1p(x) is much closer to the true result of ln(1+ x) than the floating-point evaluation of log(1.0+x)
Special cases:
1. If the argument is NaN or less than -1, then the result is NaN.
2. If the argument is positive infinity, then the result is positive infinity.
3. If the argument is negative, then the result is negative infinity.
4. If the argument is zero, then the result is a zero with the same sign as the argument.
Parameters: One parameter is required for this method.
x: a value.
Returns: The value ln(x + 1), the natural log of x + 1
For Example:
Math.log1p(100) = > It returns 4.61512051684126
Approach
Java
public class Log1p {public static void main(String[] args) {double x = 100;System.out.println(Math.log1p(x));}}
Output:
4.61512051684126
No comments:
Post a Comment