This is the range of integers in PHP +2147483647 to -2147483648. When any bitwise operation yields a result beyond these boundaries (more than +2147483647 or less than -2147483648), an overflow/underflow occurs. For example:-
The bitwise operator ^ which does the operation XOR on the operands, should return the first number when the second number is 0 (Order is not important). So, the following code should output the number
2147483647 which is what the value of $t1 is.
CODE
<?
$t1 = 2147483647;
$t2 = 0;
$t3 = $t1 ^ t2;
echo $t3;
?>
Now, if we make $t1 greater than the integer boundary for PHP by substituting the value to
2147483648 (which is one greater than the upper limit), the output is
-2147483648. As you can see, an overflow occured and the result changed sign turning to the other side. If, $t1 had a value of
2147483649 (two more than the limit), the output would be
-2147483647. This is ok and desired by the Page Rank script during the cheksum calculation.
But, cosider the underflow scenario:-
CODE
<?
$t1 = -2147483648;
$t2 = 0;
$t3 = $t1 ^ t2;
echo $t3;
?>
Here, $t1 is on the edge of the lower limit and the output would be
-2147483648. When we set $t1 to
-2147483649 (one less than the limit) an underflow should happen and the sign should again change causing the output to be
2147483647. This happens on my localhost running on Win XP x86, but not on the Astahost servers. There the result is
-2147483648 (the lower bound), no matter how much underflow occurs.
Does anybody have an idea on how to tackle this problem?
Reply