PHP automatically converts integers that would overflow to floats, is there a way to stop it from doing that and ensure proper wrapping behaviour? Throwing in a & 0xFFFFFFFF doesn’t help, it happens too late, after the low bits have already been rounded away in the float.
PHP automatically converts integers that would overflow to floats, is there a way to
Share
You can’t prevent the float conversion, but you could detect if an overflow occurred by seeing if the result is > PHP_INT_MAX (or simply checking if the result is_float!)
You could perhaps use the GMP extension which allows arbitrary length integers, and handle the overflowing yourself when you exceed 232