php – 使用bc_math或GMP计算根

我在使用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()也不起作用.

解决方法:

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

bcpow( '4', '0.5' )

这有帮助吗?

编辑:user contributed notes in the manual page确认它不支持非整数指数.

经过快速搜索后,我确实遇到了这个discussion of a PHP N-th root algorithm,所以也许这就是你所需要的.

上一篇:python – 任何地方的Gmpy文档?


下一篇:如何在Mac OS X 10.6.6上启用php-gmp? (没有macports)