strictmath_Java StrictMath log()方法与示例

strictmath

StrictMath类log()方法 (StrictMath Class log() method)

  • log() method is available in java.lang package.

    log()方法在java.lang包中可用。

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

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

  • log() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get any error.

    log()方法是静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出现任何错误。

  • log() method does not throw any exception.

    log()方法不会引发任何异常。

Syntax:

句法:

    public static double log(double d);

Parameter(s):

参数:

  • double d – represents the double type argument.

    double d –表示double类型的参数。

Return value:

返回值:

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

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

Note:

注意:

  • If we pass NaN, method returns NaN.

    如果传递NaN,则方法返回NaN。

  • If we pass a value which is less than 0, method returns NaN.

    如果传递的值小于0,则方法返回NaN。

  • If we pass an infinity, method returns the infinity.

    如果传递无穷大,则方法将返回无穷大。

  • If we pass 0, method returns a negative infinity.

    如果传递0,则方法返回负无穷大。

Example:

例:

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

public class Log {
    public static void main(String[] args) {
        // variable declarations
        double d1 = 7.0 / 0.0;
        double d2 = 0.0;
        double d3 = -0.6;
        double d4 = 124.68;

        // Display previous value of d1,d2,d3 and d4  
        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("StrictMath.log(d3): " + StrictMath.log(d3));

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

        // Here, we will get (-Infinity) because we are 
        // passing parameter whose value is (0.0)
        System.out.println("StrictMath.log(d2): " + StrictMath.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("StrictMath.log(d4): " + StrictMath.log(d4));
    }
}

Output

输出量

d1: Infinity
d2: 0.0
d3: -0.6
d4: 124.68
StrictMath.log(d3): NaN
StrictMath.log(d1): Infinity
StrictMath.log(d2): -Infinity
StrictMath.log(d4): 4.825750454899136


翻译自: https://www.includehelp.com/java/strictmath-log-method-with-example.aspx

strictmath

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值