📜  Java Math log10()

📅  最后修改于: 2020-10-06 09:34:05             🧑  作者: Mango

Java Math log10()方法计算指定值的以10为底的对数,然后将其返回。

log10()方法的语法为:

Math.log10(double x)

在这里, log10()是静态方法。因此,我们直接使用类名称Math调用该方法。


log10()参数
  • x-要计算其对数的值

log10()返回值
  • 返回x的以10为底的对数
  • 如果x为NaN或小于零,则返回NaN
  • 如果x为正无穷大,则返回正无穷大
  • 如果x为零,则返回负无穷大

注意log10(10 n ) = n ,其中n是整数。


示例:Java Math.log10()
class Main {
  public static void main(String[] args) {

    // compute log10() for double value
    System.out.println(Math.log10(9.0));       // 0.9542425094393249

    // compute log10() for zero
    System.out.println(Math.log10(0.0));       // -Infinity

    // compute log10() for NaN
    double nanValue = Math.sqrt(-5.0);
    System.out.println(Math.log10(nanValue));  // NaN

    // compute log10() for infinity
    double infinity = Double.POSITIVE_INFINITY;
    System.out.println(Math.log10(infinity));  // Infinity

    // compute log10() for negative numbers
    System.out.println(Math.log(-9.0));      // NaN

    //compute log10() for 103
    System.out.println(Math.log10(Math.pow(10, 3)));  // 3.0

  }
}

在上面的示例中,请注意以下表达式:

Math.log10(Math.pow(10, 3))

在这里, Math.pow(10, 3)返回10 3 。要了解更多信息,请访问Java Math.pow()。


推荐教程

  • Java Math.log()
  • Java Math.log1p()