PHP 4.0 Bug #6951: (Too) large integer calculations return bogus values ?

From: Date: Sat, 30 Sep 2000 00:43:11 +0000
Subject: PHP 4.0 Bug #6951: (Too) large integer calculations return bogus values ?
Groups: php.dev 
Request: Send a blank email to php-dev+get-33885@lists.php.net to get a copy of this message
From: albert@friendly.net Operating system: Linux 2.2.17 on Intel i686 Apache PHP version: 4.0.1pl2 PHP Bug Type: Variables related Bug description: (Too) large integer calculations return bogus values ? [ Linux 2.2.17 on Intel i686 Apache ] <?php // $ip = $mask = $net = 0; settype($ip, "integer"); settype($mask, "integer"); settype($net, "integer"); $ip = 3249287308; // or in my case as a result of some calculations $mask = 4294967288; // or as a result of 256*256*256*256 $net = ($ip & $mask); echo $net; // yields result: -2147483648 /* While the C code that should work alike returns the correct result: -1045679992 (okay gcc warns us: 'decimal constant is so large that it is unsigned') #include <stdio.h> int main() { int ip=3249287308, mask=4294967288, net; net=ip & mask; printf("%i\n", net); return(0); } */ ?>

« previous php.dev (#33885) next »