Java Math log() method with example
The java.lang.Math.log() method returns the natural logarithm (base e) of a double value as a parameter. There are various cases :
- If the argument is NaN or less than zero, then the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is positive zero or negative zero, then the result is negative infinity.
Syntax :
public static double log(double a)
Parameter :
a : User input
Return :
This method returns the value ln a.
Example :To show working of java.lang.Math.log() method.
// Java program to demonstrate working // of java.lang.Math.log() method import java.lang.Math; class Gfg { // driver code public static void main(String args[]) { double a = -2.55; double b = 1.0 / 0; double c = 0, d = 145.256; // negative integer as argument, output NAN System.out.println(Math.log(a)); // positive infinity as argument, output Infinity System.out.println(Math.log(b)); // positive zero as argument, output -Infinity System.out.println(Math.log(c)); // positive double as argument System.out.println(Math.log(d)); } } |
chevron_right
filter_none
Output:
NaN Infinity -Infinity 4.978497702968366
Recommended Posts:
- Java.math.BigInteger.modInverse() method in Java
- Java.math.BigInteger.probablePrime() method in Java
- Java Math exp() method with Example
- Java Math getExponent() method with Example
- Java Math nextAfter() method with Example
- Java Math negateExact() method
- Java Math asin() method with Example
- Math fma() method in Java with Examples
- Java Math abs() method with Examples
- Java Math subtractExact(int a , int b) method
- Java Math expm1() method with Example
- Java Math addExact(int a, int b) method
- Java Math max() method with Examples
- Java Math incrementExact() method
- Math scalb() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



