bcpow 和 pow 有什么区别?

发布于 2024-10-20 01:59:51 字数 173 浏览 6 评论 0原文

有人可以向我解释一下我是否应该使用 bcpow() 而不是 pow() 以及为什么?

据我了解,并非所有 php 安装都启用了 bcmath。因此,如果我编写一个开源项目,并且希望拥有尽可能少的依赖项/要求,我宁愿在代码中使用 pow() 。

但是使用 pow() 相对于 bcpow() 有何缺点?

Can someone explain to me if I should use bcpow() instead of pow() and why?

I understand that not all installations of php have bcmath enabled. So if I write an open source project, and want to have as few dependencies/requirements as possible, I would rather use pow() in my code.

But what are the downsides to using pow() over bcpow()?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

子栖 2024-10-27 01:59:51

bcpow()BCMath 任意精度数学 库。

引用它的手册的介绍:

对于任意精度的数学
PHP 提供了二进制计算器
支持任意大小的数字
精度
,表示为字符串。

On the other hand, [**`pow()`**][3] is limited to [floats][4], which have a limited size *(quoting)* :

浮点数的大小是
依赖于平台,尽管最大
~1.8e308,精度为
大约 14 位十进制数字是常见的
值(64 位 IEEE 格式)

Generally, you'll work with `pow()` and other float-based functions *(which are probably faster, and are always enabled)* ; but, if you need to handle very big number, you'll have to work with `bcpow()`.

bcpow() is a function of the BCMath Arbitrary Precision Mathematics library.

Quoting the introduction of it's manual :

For arbitrary precision mathematics
PHP offers the Binary Calculator which
supports numbers of any size and
precision
, represented as strings.

On the other hand, [**`pow()`**][3] is limited to [floats][4], which have a limited size *(quoting)* :

The size of a float is
platform-dependent, although a maximum
of ~1.8e308 with a precision of
roughly 14 decimal digits is a common
value (the 64 bit IEEE format)

Generally, you'll work with `pow()` and other float-based functions *(which are probably faster, and are always enabled)* ; but, if you need to handle very big number, you'll have to work with `bcpow()`.

江挽川 2024-10-27 01:59:51

根据 手册bc* 功能是

[...] 任意精度数学 PHP 提供了二进制计算器,它支持任意大小和精度的数字(以字符串表示)。

pow() 仅限于其运行的系统上支持的最大数字表示形式。

According to the manual the bc* functions are

[...] arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings.

pow() is limited to the maximum supported numeric representation on the system it runs on.

泪眸﹌ 2024-10-27 01:59:51

bcpow 用于任意精度值。作为第三个参数,您可以指定逗号后的位数。

bcpow is used for arbitrary precision values. As a third parameter you can specify a number of digits after coma.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文