开发者

32 bit unsigned int php

开发者 https://www.devze.com 2022-12-24 12:49 出处:网络
Does anyone know of a class/library/e开发者_如何学运维tc. that can simulate 32 bit unsigned integers on a 32 bit platform in 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消