32 bit - PHP intval() changes number NOT 2147483647 -
I am running PHP 5.3.13 and when I execute
php - R "Echo Infral (99 99 99 99 99);"
This produces 1410065407.
When I execute
php -r "echo intval (PHP_INT_MAX);"
This produces 2147483647.
Why is the small integer causing my code to cause some issues?
In your case, value 9999999999
a name
. You can verify it with var_dump (99 99 99 99 99)
. When it is placed in signed integer, the value is reduced to 32 bits which gives the value 1410065407
.
You can manually verify this calculation or use the GMP math extension:
$ num = gmp_init ("9999999999"); $ Beats = GMP_paw (2, 32); Var_dump (gmp_strval (gmp_mod ($ num, $ bits)); // string (10) "1410065407"
Comments
Post a Comment