在Java中,Math.log()方法用于计算一个数的自然对数。它遵循以下规则处理特殊值:
Math.log()方法将返回负无穷大(Double.NEGATIVE_INFINITY)。Double.POSITIVE_INFINITY),Math.log()方法将返回正无穷大(Double.POSITIVE_INFINITY)。Math.log()方法将返回NaN。例如:
System.out.println(Math.log(-1)); // 输出 -Infinity
System.out.println(Math.log(0)); // 输出 -Infinity
System.out.println(Math.log(Double.POSITIVE_INFINITY)); // 输出 Infinity
System.out.println(Math.log(Double.NaN)); // 输出 NaN