Java中的StrictMath log1p()方法

这个 JAVA朗,数学。log1p() 是Java中的内置方法,用于接受双精度值作为参数并返回 自然对数 参数和1之和。

null

语法:

public static double log1p(double x)

参数: 该函数接受双倍值x作为参数,并计算 自然算法 (1+x)。 返回值: 此方法返回值 ln(1+x) .结果 log1p(x) 几乎与 ln(1+x) 对于小值 十、 比浮点计算 对数(1.0+x) . 考虑以下情况:

  • 函数返回 正无穷大 如果论点是正确的 正无穷大 .
  • 函数返回 负无穷大 对于 负无穷大 .
  • 函数返回 如果论点是正确的 小于-1 .
  • 函数返回 如果参数为 .

例如:

Input : 2018.0Output : 7.610357618312838Input : -4743.0Output : NaN

下面的程序说明了java的工作原理。朗,数学。log1p()函数: 项目1: 在这个程序中,传递有限且非零的参数。

JAVA

// Java Program to illustrate
// StrictMath.log1p() function
import java.io.*;
import java.lang.*;
class GFG {
public static void main(String[] args)
{
double val1 = 2018.00567 , val2 = 99999.0 ;
System.out.println( "Natural Logarithm of " +
(val1 + 1 ) + " is " + StrictMath.log1p(val1));
System.out.println( "Natural Logarithm of " +
(val2 + 1 ) + " is " + StrictMath.log1p(val2));
}
}


输出:

Natural Logarithm of 2019.00567 is 7.610360426629845Natural Logarithm of 100000.0 is 11.512925464970229

项目2: 在这个程序中,传递无限和负参数。

JAVA

// Java Program to illustrate
// StrictMath.log1p() function
import java.io.*;
import java.lang.*;
class GFG {
public static void main(String[] args)
{
double val1 = 201800 / ( 0.0 ), val2 = - 4743.0 ;
System.out.println( "Natural Logarithm of " +
(val1 + 1 ) + " is " + StrictMath.log1p(val1));
System.out.println( "Natural Logarithm of " +
(val2 + 1 ) + " is " + StrictMath.log1p(val2));
}
}


输出:

Natural Logarithm of Infinity is InfinityNatural Logarithm of -4742.0 is NaN

参考: https://docs.oracle.com/javase/8/docs/api/java/lang/StrictMath.html#log1p()

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享