[PHP-DEV] PHP 4.0 Bug #6951: (Too) large integer calculations return bogus values ? From: albert <email protected>
Date: 09/29/00

From: albert <email protected>
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);
}
*/
  
?>

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>