//直接使用Math库 public static double log(double a)
Returns the natural logarithm (base e) of a
double
value. Special cases:- If the argument is NaN or less than zero, then the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is positive zero or negative zero, then the result is negative infinity.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
- Parameters:
a
- a value Returns:- the value ln
a
, the natural logarithm ofa
.
public static double logN(double N)
{
if(N == 0 || N == 1)return 0.0; // 0的阶乘和1的阶乘都为1
else {
return Math.log(N)+logN(N-1);
}
}