What is Math log10(double a) in Java?

log10(double a) is a public static method in java.lang.Math that is used to compute the base 10 logarithm of the argument value. The method accepts a double type value as a parameter and returns a double-precision number, i.e., 64-bit.

By default, the java.lang package is loaded, so there is no need to import this package into your program.

Syntax


static double log10(double a)

Parameters

  • Double precision number: A 64-bit long double type variable.

Return value

  • Logarithm: A double type common logarithm of argument value.

Note: In mathematics, logarithm with base 10 is called common logarithm, i.e., log10(10)=1log_{10}(10)= 1, log10(2)=0.3010log_{10}(2)= 0.3010.

Special cases

  1. double value: If the argument is a double type value x, log10 will return log_{10}(x).
  2. NaN: If the argument is NaN(no-argument), log10 will return NaN.
  3. less than zero: If the argument is a negative value or less than zero, log10 will return NaN.
  4. positive infinity: If the argument value is positive infinity, log10 will return positive infinity.
  5. positive zero or negative zero: If the argument value is positive zero or negative zero, log10 will return negative infinity.
  6. exponential number: If the argument value is an exponential number like 10^{n} for integer n, then the result will be n.

Example

This code illustrates multiple cases of the log10() method with different argument values, as discussed above.

class EdPresso {
public static void main( String args[] ) {
// double type number as argument
System.out.println("double type argument: " + Math.log10(2.0));
// negative number as argument
System.out.println("Negative argument: " + Math.log10(-10));
// positive infinity as argument
System.out.println("Positive infinity :" + Math.log10(Double.POSITIVE_INFINITY));
// Zero as argument
System.out.println("Negative or Positive Zero: " + Math.log10(0));
// exponential number as argument
System.out.println("Exponential number: " + Math.log10(10E+0));
}
}

Free Resources