ID:               38045
 Updated by:       [EMAIL PROTECTED]
 Reported By:      igor at oleinikov dot ru
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: FreeBSD 6.1 Release
 PHP Version:      5.1.4
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

32bit


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

[2006-07-09 09:30:38] igor at oleinikov dot ru

Description:
------------
When I want to calculate integer summ of two integers with overflow, I
get unexpected result, becouse result converts to float, then converts
to integer.

Important: I've tested this example on two systems with same versions
of php (5.1.4) and different versions of freebsd (4.11 and 6.1).
On last operation [$b = (int)($a + $a)], freebsd 4.11 produce expected
result: int(0), but freebsd 6.1 produce minimal integer (-2147483648).

How can I implement algorithm with integer mathematics, that requires
overflows? i have it successfully working on freebsd 4.11, but it don't
work on freebsd 6.1 ((

Reproduce code:
---------------
$a = 0x80000000; //i'd like it would integer, but it float ;)
var_dump($a, dechex($a));
$a = (int)0x80000000; //ok, i'll make it integer myself
var_dump($a, dechex($a));
$b = $a + $a; //int + int = int ?
var_dump($b, dechex($b));
$b = (int)($a + $a);
var_dump($b, dechex($b));


Expected result:
----------------
int(-2147483648) string(8) "80000000"
int(-2147483648) string(8) "80000000"
int(0) string(8) "0" //expected, int + int = int with overflow
int(0) string(8) "0" //expected, conversion with overflow

Actual result:
--------------
float(2147483648) string(8) "80000000" // expected int
int(-2147483648) string(8) "80000000" // when I convert to int myself
float(-4294967296) string(8) "80000000" //expected int, but it
overflows and converts to float
int(-2147483648) string(8) "80000000"


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


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

Reply via email to