Java.lang.StrictMath.log1p() 方法
描述
java.lang.StrictMath.log1p() 方法返回参数和 1 的自然对数。对于较小的值 x,log1p(x) 的结果 比 log(1.0+x) 的浮点求值更接近 ln(1 + x) 的真实结果。它包括一些情况 −
- 如果参数为 NaN 或小于 -1,则结果为 NaN。
- 如果参数为正无穷大,则结果为正无穷大。
- 如果参数为负数,则结果为负无穷大。
- 如果参数为零,则结果为零,符号与参数相同。
声明
以下是 java.lang.StrictMath.log1p() 方法的声明。
public static double log1p(double x)
参数
x − 这是一个值。
返回值
此方法返回值 ln(x + 1),即 x + 1 的自然对数。
异常
NA
示例
下面的例子展示了 java.lang.StrictMath.log1p() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
double d1 = 90 , d2 = 0.0 , d3 = (1.0/0.0);
// returns the natural logarithm of the sum of the argument and 1
double log1pValue = StrictMath.log1p(d1);
System.out.println("Logarithm value of double (d1 + 1) with base 10 :
" + log1pValue);
log1pValue = StrictMath.log1p(d2);
System.out.println("Logarithm value of double (d2 + 1) with base 10 :
" + log1pValue);
log1pValue = StrictMath.log1p(d3);
System.out.println("Logarithm value of double (d3 + 1) with base 10 :
" + log1pValue);
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Logarithm value of double (d1+1) with base 10 : 4.51085950651685 Logarithm value of double (d2+1) with base 10 : 0.0 Logarithm value of double (d3+1) with base 10 : Infinity

