gpt4 book ai didi

php - 使用 bc_math 或 GMP 计算根

转载 作者:可可西里 更新时间:2023-10-31 23:44:29 25 4
gpt4 key购买 nike

我在使用 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 它说你必须将它们作为字符串传递,即

bcpow( '4', '0.5' )

这有帮助吗?

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

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

关于php - 使用 bc_math 或 GMP 计算根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1522207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com