Math.pow(0.0, 0.0)
在 Java 中返回 1 这是错误的。0^0 未定义。windows计算器也存在同样的问题(我用的是Win7)。这是为什么?
Mathematica 和我的卡西欧科学计算器一样将其声明为错误,为什么不使用 java 或 Win 计算器……这是一个错误吗?
0^0 = 1 在许多情况下被认为是一个合理的定义。有关支持和反对它的论点列表,请参阅http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_power_of_zero
因为这正是Javadocs所说的:
public static double pow(double a, double b)
返回第一个参数的第二个参数次方的值。特殊情况:
* 如果第二个参数为正零或负零,则结果为 1.0。
Java defines it that way. That's all you can really say.
However, mathematically it is an undefined quantity. One way to see why is to write
x = 0 ^ 0
where I've used ^ to represent exponentiation. Taking logarithms,
log x = 0 log 0
I've done this since every mathematician accepts that log 0 is undefined and so it follows that log x and therefore x are undefined too. (Mathematically it's called a singularity and a mathematician will tell you that it's one of the worst singularities you can encounter).
函数行为的确切定义在http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#pow(double,%20double)
你会在这里看到
public static double pow(double a,
double b)
Returns the value of the first argument raised to the power of the second argument. Special cases:
If the second argument is positive or negative zero, then the result is 1.0.
不是错误 - 这是设计使然。