32 bit unsigned int php
Does anyone know of a class/library/e开发者_如何学运维tc. that can simulate 32 bit unsigned integers on a 32 bit platform in PHP? I'm porting a C lib into PHP and it uses a lot of integers that are greater than the maximum for 32 bit signed int.
Try the BC Math Library, which "supports numbers of any size and precision, represented as strings."
Good luck!
Why can't you write
modulo(a+b,2^32)
or its PHP equivalent for a, b being "unsigned" integers you are trying to "unsigned integer add", similarly for subtract, multiply, divide, ...? You can of course hide this in a function add_unsigned to make the code a bit clearer.
Do you really need it? php will convert to float if you go out of bounds of an int.
http://www.php.net/manual/en/language.types.integer.php
var_dump(PHP_INT_MAX);
$int = PHP_INT_MAX;
var_dump($int + $int);
精彩评论