What is the Math log() function in Java?
The static method log() in java.lang.Math class is used to calculate the x and computes .
Syntax
static double log(double x)
Parameters
x: It takes a number of type double.
Return value
log() will return a natural logarithm of double type.
- The result is
NaNif the argument value is less than zero or NaN. - The result is positive infinity (+∞) if the argument value is positive infinity.
- The result is negative infinity (-∞) if the argument value is a positive zero (+0) or a negative zero (-0).
Code
- Case #1: A positive value of type double is supplied as an argument.
log()will return the natural log. - Case #2: A negative value is passed in and
log()will return NaN. - Case #3: Positive infinity is supplied as an argument and
log()will return infinity. - Case #4: Negative infinity is supplied as an argument and
log()will return NAN.
// Load math libraryimport java.lang.Math;// Main classclass EdPresso{public static void main( String args[] ) {System.out.println(Math.log(89.3));}}