用bc_math或GMP计算根 [英] Calculating roots with bc_math or GMP

查看:128
本文介绍了用bc_math或GMP计算根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用bc_math计算相当大的根数时遇到麻烦,例如:

I'm having trouble calculating roots of rather large numbers using bc_math, example:

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

Does anybody knows how I can circumvent this? gmp_pow() also doesn't work.

推荐答案

我不是PHP程序员,而是查看

I'm not a PHP programmer but looking at the manual it says you have to pass them in as strings i.e.

bcpow( '4', '0.5' )

有帮助吗?

编辑:用户提供的注释在手册页中,确认它不支持非整数指数.

Edit: The user contributed notes in the manual page confirm that it doesn't support non-integer exponents.

我确实遇到了这个讨论第N个PHP根算法的问题快速搜索后,也许这就是您所需要的.

I did come across this discussion of a PHP N-th root algorithm after a quick search so perhaps that's what you require.

这篇关于用bc_math或GMP计算根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆