java math log_Java Math类静态double log(double d)示例

java math log

数学类静态双对数(double d) (Math Class static double log(double d))

  • This method is available in java.lang package.

    此方法在java.lang包中可用。

  • This method is used to return the logarithm of the given (base e) of the given argument.

    此方法用于返回给定参数的给定(以e为底)的对数。

  • This is a static method so it is accessible with the class name too.

    这是一个静态方法,因此也可以使用类名进行访问。

  • The return type of this method is double, it returns the logarithm (base e) of the given argument.

    此方法的返回类型为double,它返回给定参数的对数(以e为底)。

  • In this method, we pass only one parameter as an argument of double type.

    在此方法中,我们仅传递一个参数作为double类型的参数。

  • This method does not throw any exception.

    此方法不会引发任何异常。

Syntax:

句法:

    public static double log(double d){
    }

Parameter(s): It accepts a double value, whose logarithm to be found.

参数:它接受一个双精度值,其对数将被找到。

Return value:

返回值:

The return type of this method is double, it returns the logarithm (base e).

此方法的返回类型为double ,它返回对数(以e为底)。

Note:

注意:

  • If we pass "NaN", it returns "NaN".

    如果我们传递“ NaN”,则返回“ NaN”。

  • If we pass less than 0, it returns "NaN".

    如果传递的值小于0,则返回“ NaN”。

  • If we pass positive infinity, it returns the same value (positive infinity).

    如果我们传递正无穷大,它将返回相同的值(正无穷大)。

  • If we pass zero (0 or -0), it returns negative infinity.

    如果我们传递零(0或-0),它将返回负无穷大。

Java程序演示log(double d)方法的示例 (Java program to demonstrate example of log(double d) method)

// Java program to demonstrate the example of 
// log(double d) method of Math Class.

public class LogMethod {
    public static void main(String[] args) {
        // Here we are declaring few variables
        double d1 = 7.0 / 0.0;
        double d2 = 0.0;
        double d3 = -0.6;
        double d4 = 124.68;

        // displaying values
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);
        System.out.println("d4: " + d4);

        // Here , we will get (NaN) because we are 
        // passing parameter whose value is less than 0(-0.6)
        System.out.println("Math.log(d3): " + Math.log(d3));

        // Here , we will get (infinity) because we are 
        // passing parameter whose value is (infinity)
        System.out.println("Math.log(d1):" + Math.log(d1));

        // Here , we will get (-Infinity) because we are 
        // passing parameter whose value is (0.0)
        System.out.println("Math.log(d2) :" + Math.log(d2));

        // Here , we will get (e raised to the power of the given argument) 
        // and we are passing parameter whose value is (1274.68)
        System.out.println("Math.log(d4): " + Math.log(d4));
    }
}

Output

输出量

E:\Programs>javac LogMethod.java

E:\Programs>java LogMethod
d1: Infinity
d2: 0.0
d3: -0.6
d4: 124.68
Math.log(d3): NaN
Math.log(d1):Infinity
Math.log(d2) :-Infinity
Math.log(d4): 4.825750454899136


翻译自: https://www.includehelp.com/java/math-class-static-double-log-double-d-with-example.aspx

java math log

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值