ID:               49330
 Updated by:       sjo...@php.net
 Reported By:      john at sinteur dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Math related
 Operating System: FreeBSD, Mac OS
 PHP Version:      5.2.10
 New Comment:

Thank you for your report.

The behavior you report is not a bug. If PHP encounters a number beyond
the bounds of the integer  type, it will be interpreted as a float
instead. That is why it is possible to have $xxx bigger than
PHP_INT_MAX. Operands of modulus are converted to integers (by stripping
the decimal part) before processing. That is why the $xxx is wrapped
around for the modulo operator.

PHP_INT_MAX % $a == 2147483647 % $a
(PHP_INT_MAX + 1) % $a == -2147483648 % $a




Previous Comments:
------------------------------------------------------------------------

[2009-08-22 16:22:33] john at sinteur dot com

Description:
------------
Counting doesn't appear to wrap properly at 32 bits





Reproduce code:
---------------
$xxx=0;

while (true) {

$xxx++;
if ($xxx%10000000 == 0)
        print $xxx . "\n";

}

Expected result:
----------------
10000000
20000000
30000000
40000000
50000000
...(etc)
2120000000
2130000000
2140000000
2150000000
2160000000
2170000000
2180000000


Actual result:
--------------
10000000
20000000
30000000
40000000
50000000
...(etc)
2120000000
2130000000
2140000000
2154967296
2164967296
2174967296
2184967296



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49330&edit=1

Reply via email to