使用bc_math或GMP计算根

时间:2009-10-05 20:28:38

标签: php math gmp bcmath

我无法使用bc_math计算相当大数字的根,例如:

 - pow(2, 2)        // 4, power correct
 - pow(4, 0.5)      // 2, square root correct
 - bcpow(2, 2)      // 4, power correct
 - bcpow(4, 0.5)        // 1, square root INCORRECT

有谁知道我怎么能绕过这个? gmp_pow()也不起作用。

1 个答案:

答案 0 :(得分:1)

我不是PHP程序员,但是看the manual它说你必须把它们作为字符串传递给它。

bcpow( '4', '0.5' )

这有帮助吗?

修改user contributed notes in the manual page确认它不支持非整数指数。

我在快速搜索后遇到了discussion of a PHP N-th root algorithm,所以也许这就是你需要的。