PHP 中的极大整数

发布于 2024-09-20 00:15:55 字数 601 浏览 8 评论 0原文

可能的重复:
在 PHP 中处理大数。

我运行一个完全无用的 Facebook 应用程序。我对 PHP 对整数的支持有疑问。基本上,用户给自己的分数是荒谬的。目前的“王”有102,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,002,557,529,927点。

PHP 似乎不能很好地处理大整数。当有人尝试添加超过一定数量的点时,它将失败,因为 PHP 将这些数字视为无限。

是否有一些数学库可以处理大得离谱的数字?我应该将数字视为字符串并编写自己的字符串吗?

我们所说的数字长度为 2^20 位或更长。它们不需要准确(任何错误通常都会归因于应用程序的低质量),也不需要具有高性能。我只需要一些允许更长数字的东西。

(对于那些好奇的人,我们将数据存储在云端,因此存储成本不是一个大问题。)

Possible Duplicate:
Working with large numbers in PHP.

I run a completely useless Facebook app. I'm having a problem with PHP's support for integers. Basically, users give themselves ridiculous numbers of points. The current "king" has 102,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,002,557,529,927 points.

PHP does not seem to play well with large integers. When someone tries to add more than a certain amount of points it will fail because PHP treats those numbers as infinite.

Is there some math library for working with ridiculously large numbers? Should I treat the numbers as strings and write my own?

We're talking numbers which are 2^20 digits in length or longer. They don't need to be accurate (any errors are chalked up to the low quality of the app in general) nor does it need to be high performance. I just need something which allows much longer numbers.

(For those of you who are curious, we store our numbers in the cloud, so storage cost isn't a huge issue.)

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

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

发布评论

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

评论(2

甜心 2024-09-27 00:15:55

PHP 使用浮点数或带符号的 32 位整数来存储数字。显然这还不够。您可以使用任意精度算术来存储这些大数。有关详细信息,请参阅有关 BC Math 的 PHP 书籍:

http://php.net/manual/ en/book.bc.php

PHP uses floats, or signed 32-bit ints to store numbers. Clearly this is not enough. You can use arbitrary precision arithmetic to store these large numbers. See the PHP book on BC Math for more information:

http://php.net/manual/en/book.bc.php

萌辣 2024-09-27 00:15:55

用于处理大数的两个 PHP 库是 BC Math< /strong> 和 GMP

Two PHP libraries for working with large numbers are BC Math and GMP.

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