这是一个有趣的问题.如果您查看Java Math类的源代码,您会发现它调用StrictMath.pow(double1,double2),StrictMath的签名是public static native pow(double a,double b);
所以,最终,这是一个真正的本地电话,可能会因平台而有所不同.然而,在某个地方有一个实现,并不是很容易看.这里是函数的描述和函数本身的代码:
注意
看数学,试图理解它可能不可避免地会导致更多的问题.但是,通过在Java Math Function Source Code搜索这个Github并扫描数学概要,你可以更好地理解本机功能.快乐探索:)
方法说明
Method: Let x = 2 * (1+f)
1. Compute and return log2(x) in two pieces:
log2(x) = w1 + w2,
where w1 has 53-24 = 29 bit trailing zeros.
2. Perform y*log2(x) = n+y' by simulating muti-precision
arithmetic, where |y'|<=0.5.
3. Return x**y = 2**n*exp(y'*log2)
特殊情况
1. (anything) ** 0 is 1
2. (anything) ** 1 is itself
3. (anything) ** NAN is NAN
4. NAN ** (anything except 0) is NAN
5. +-(|x| > 1) ** +INF is +INF
6. +-(|x| > 1) ** -INF is +0
7. +-(|x| < 1) ** +INF is +0
8. +-(|x| < 1) ** -INF is +INF
9. +-1 ** +-INF is NAN
10. +0 ** (+anything except 0, NAN) is +0
11. -0 ** (+anything except 0, NAN, odd integer) is +0
12. +0 ** (-anything except 0, NAN) is +INF
13. -0 ** (-anything except 0, NAN, odd integer) is +INF
14. -0 ** (odd integer) = -( +0 ** (odd integer) )
15. +INF ** (+anything except 0,NAN) is +INF
16. +INF ** (-anything except 0,NAN) is +0
17. -INF ** (anything) = -0 ** (-anything)
18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
19. (-anything except 0 and inf) ** (non-integer) is NAN
准确性
pow(x,y) returns x**y nearly rounded. In particular
pow(integer,integer)
always returns the correct integer provided it is
representable.
<