Java Math log() Method
Example
Return the natural logarithm of different numbers:
System.out.println(Math.log(6));
System.out.println(Math.log(Math.E));
System.out.println(Math.log(2));
System.out.println(Math.log(1));
System.out.println(Math.log(0));
System.out.println(Math.log(-1));
Definition and Usage
The log()
method returns the natural logarithm of a number.
The natural logarithm is the logarithm with base e. The value of e is approximately 2.718282 and it is available as the constant Math.E
in Java.
Syntax
public static double log(double number)
Parameter Values
Parameter | Description |
---|---|
number | Required. Specifies the value to calculate the logarithm for. If the value is negative, it returns NaN (Not a Number). If the value is 0, it returns -Infinity. |
Technical Details
Returns: | A double value representing the natural logarithm of a number. |
---|---|
Java version: | Any |
❮ Math Methods