From: dneilsen at davislangdon dot com dot au
Operating system: RedHat Linux 8 & 9
PHP version: 4.3.7
PHP Bug Type: Math related
Bug description: Bitwise AND operator does not work on high values
Description:
------------
I have tested this on two separate systems running Redhat 8 and redhat 9
respectively. The Redhat 9 system is running php version 4.3.4 and the
redhat 8 is running 4.3.7.
php.ini has not been altered and, in the case of the redhat 8 box (php
4.3.7), it was compiled with the following:
./configure --with-mysql --with-apxs=/www/bin/apxs
It seems that the bitwise AND operator will not work for values over
pow(2,30). In the case of power 31 it returns a negative value and in the
case of power 32 and above it returns 0.
Thank you for your time :)
Regards
Daniel Neilsen
Reproduce code:
---------------
<?
for($i=28; $i<34; $i++)
{
$vala = pow(2,$i);
$valb = pow(2,$i);
$result = $vala & $valb;
echo "$i - $vala & $valb = $result<br>";
}
Expected result:
----------------
28 - 268435456 & 268435456 = 268435456
29 - 536870912 & 536870912 = 536870912
30 - 1073741824 & 1073741824 = 1073741824
31 - 2147483648 & 2147483648 = 2147483648
32 - 4294967296 & 4294967296 = 4294967296
33 - 8589934592 & 8589934592 = 8589934592
Actual result:
--------------
28 - 268435456 & 268435456 = 268435456
29 - 536870912 & 536870912 = 536870912
30 - 1073741824 & 1073741824 = 1073741824
31 - 2147483648 & 2147483648 = -2147483648
32 - 4294967296 & 4294967296 = 0
33 - 8589934592 & 8589934592 = 0
--
Edit bug report at http://bugs.php.net/?id=28691&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28691&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28691&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28691&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28691&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28691&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28691&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28691&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28691&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28691&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28691&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28691&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28691&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28691&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28691&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28691&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28691&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28691&r=float