PHP中的极大整数 [英] Extremely Large Integers in PHP

查看:129
本文介绍了PHP中的极大整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
使用PHP处理大量数字.

Possible Duplicate:
Working with large numbers in PHP.

我运行了一个完全无用的Facebook应用程序. PHP对整数的支持存在问题.基本上,用户给自己的分数很可笑.当前的国王"拥有102,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,002,557,529,927点.

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似乎不适用于大整数.当某人尝试添加多于一定数量的点时,它将失败,因为PHP将这些数字视为无穷大.

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?

我们所说的数字是2 ^ 20位数字,长度或更长.他们不需要准确(通常将任何错误归结为应用程序的低质量),也不需要是高性能.我只需要一些允许更长的数字的东西.

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.)

推荐答案

PHP使用浮点数或带符号的32位整数来存储数字.显然,这还不够.您可以使用任意精度算术来存储这些大数.有关更多信息,请参见BC Math上的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

这篇关于PHP中的极大整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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