
Java Math log10()方法计算指定值的以10为底的对数,然后将其返回。
log10()方法的语法为:
Math.log10(double x)
注意:该log10()方法是静态方法。因此,我们可以使用类名直接调用该方法Math。
log10()参数
- x - 要计算其对数的值 
log10()返回值
- 返回x的以10为底的对数 
- 如果x为NaN或小于零,则返回NaN 
- 如果x为正无穷大,则返回正无穷大 
- 如果x为零,则返回负无穷大 
注意:当n是整数时,值为 log10(10n) = n
示例:Java Math.log10()
class Main {
  public static void main(String[] args) {
    //计算双精度值的log10()
    System.out.println(Math.log10(9.0));       // 0.9542425094393249
    //计算0的log10()
    System.out.println(Math.log10(0.0));       // -Infinity
    //计算NaN的log10()
    double nanValue = Math.sqrt(-5.0);
    System.out.println(Math.log10(nanValue));  // NaN
    //计算无穷大的log10()
    double infinity = Double.POSITIVE_INFINITY;
    System.out.println(Math.log10(infinity));  // Infinity
    //计算负数的log10()
    System.out.println(Math.log(-9.0));      // NaN
    //计算10的3次方的log10()
    System.out.println(Math.log10(Math.pow(10, 3)));  // 3.0
  }
}在上面的示例中,请注意以下表达式:
Math.log10(Math.pow(10, 3))
在这里,Math.pow(10, 3)返回103。要了解更多信息,请访问Java Math.pow()。
