Java Math log10() Method
The log10() method of Math class returns the base 10 logarithmic value for the specified double argument.
Syntax:
public static double log10(double a)
Parameters:
The parameter ‘a’ represents a double value.
Return Value:
The log10() method returns the base 10 logarithm of a.
Special cases of the log10() method are as follows:
- It returns NaN, if the argument is NaN or less than zero.
- It returns positive infinity, if the argument passed is positive infinite.
- It returns negative infinity, if the argument passed is positive zero or negative zero.
- It returns n, if the argument is equal to 10n for integer n.
Example 1:
public class JavaMathLog10Example1 { public static void main(String[] args) { double a = 10; //returns the natural base 10 logarithm of a System.out.println("Logrithm10 value : "+Math.log10(a)); } }
Output:
Logrithm10 value : 1.0
Example 2:
public class JavaMathLog10Example2 { public static void main(String[] args) { double a = -98; //returns NaN, if the argument is NaN or less than zero System.out.println("Logrithm10 value for "+a +" : "+Math.log10(a)); } }
Output:
Logrithm10 value for -98.0 : NaN
Example 3:
public class JavaMathLog10Example3 { public static void main(String[] args) { double a = 98/0.0d; //returns positive infinity, if the argument passed is positive infinite System.out.println("Logrithm10 value for "+a +" : "+Math.log10(a)); } }
Output:
Logrithm10 value for Infinity : Infinity
Example 4:
public class JavaMathLog10Example4 { public static void main(String[] args) { double a = 0; //returns negative infinity, if the argument passed is positive or negative zero System.out.println("Logrithm10 value for "+a +" : "+Math.log10(a)); } }
Output:
Logrithm10 value for 0.0 : -Infinity
Example 5:
public class JavaMathLog10Example5 { public static void main(String[] args) { double a = 100000000; //returns n, if the argument is equal to 10n for integer n System.out.println("Logrithm10 value for "+a +" : "+Math.log10(a)); } }
Output:
Logrithm10 value for 1.0E8 : 8.0