ID:               37082
 User updated by:  oliver at teqneers dot de
 Reported By:      oliver at teqneers dot de
 Status:           Bogus
 Bug Type:         *General Issues
 Operating System: Suse Linux 10/Debian Sarge
 PHP Version:      5.1.2
 New Comment:

very sorry for the typo. now i get a float and int as well...

but why is the following expression on a 64bit true?
var_dump('9223372036854775808' == '9223372036854775806');
and this following expression on a 32-bit false?
var_dump('2147483648' == '2147483646');

on both systems one of the values var_dumps to float and the other to
int???


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

[2006-04-14 15:09:23] [EMAIL PROTECTED]

>This is not quite correct, because var_dump
>(9323372036854775808); var_dump(9323372036854775806); 
>return both float values.

Sure. 
Because 9323372036854775806 is MUCH bigger than 9223372036854775806.
Note "93.." and "92.." in the beginning.

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

[2006-04-14 15:04:01] oliver at teqneers dot de

This is not quite correct, because var_dump(9323372036854775808);
var_dump(9323372036854775806);
return both float values.
The problem here is, that the second value is NOT a float, but an
integer value because it is still in the range of a 64bit integer.

And the following expression should still not return true
vd('9223372036854775808' == '9223372036854775806')

If this is not a PHP issue, where should I look into? Compiler, OS,
...?

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

[2006-04-14 14:51:32] [EMAIL PROTECTED]

>if( (string)'9323372036854775806' == (string)'9223372036854775806' )
Adding (string) here doesn't make any sense - they ARE strings.
And numeric strings are converted to integers/floats automatically.

Both var_dump(9323372036854775808); and var_dump(932337203685477580);
produce the same result and their equality is the correct result.
Furthermore, this is something to do with the system (which is unable
to compare big floats adequately), not with PHP.
No PHP bug here.

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

[2006-04-14 13:05:30] oliver at teqneers dot de

Description:
------------
When operating at or beyond the integer limits, there is a different
behaviour between a 32bit and 64bit processor (beside the different max
value of course).

on a 32bit processor the limit is 2147483647, on a 64bit it is
9223372036854775807.

if i try to compare a STRING value like "9223372036854775807" with a
string value "9223372036854775808", which is higher, than the integer
limit, the comparison between those two returns true, but it should be
false.

This problem seems also to exists in PHP 4.4.x.

Reproduce code:
---------------
64-BIT-Source:
--------------
<?

echo 'max<br>';
echo PHP_INT_MAX.'<br>';

echo 'intval<br>';
echo intval(9223372036854775807).'<br>';
echo intval(9223372036854775808).'<br>';
echo intval(9223372036854775809).'<br>';
echo intval(9223372036854776832).'<br>';
echo intval(9223372036854776833).'<br>';

echo 'intval of string<br>';
echo intval('9223372036854775807').'<br>';
echo intval('9223372036854775808').'<br>';
echo intval('9223372036854775809').'<br>';
echo intval('9223372036854776832').'<br>';
echo intval('9223372036854776833').'<br>';

echo 'compares<br>';
if( '9223372036854775808' == '9223372036854775807' ) {
        echo 'wrong<br>';
}
if( '9223372036854775808' == '9223372036854775806' ) {
        echo 'wrong<br>';
}
if( 9223372036854775808 == 9223372036854775806 ) {
        echo 'wrong<br>';
}
if( strval('9223372036854775808') == strval('9223372036854775806') ) {
        echo 'wrong<br>';
}
if( (string)'9223372036854775808' == (string)'9223372036854775806' ) {
        echo 'wrong<br>';
}
if( (string)'9323372036854775806' == (string)'9223372036854775806' ) {
        echo 'works fine<br>';
}

?>

32-BIT-Source:
--------------
<?

echo 'max<br>';
echo PHP_INT_MAX.'<br>';

echo 'intval<br>';
echo intval(2147483647).'<br>';
echo intval(2147483648).'<br>';
echo intval(2147483649).'<br>';
echo intval(2147483650).'<br>';
echo intval(2147483651).'<br>';

echo 'intval of string<br>';
echo intval('2147483647').'<br>';
echo intval('2147483648').'<br>';
echo intval('2147483649').'<br>';
echo intval('2147483650').'<br>';
echo intval('2147483651').'<br>';

echo 'compares<br>';
if( '2147483648' == '2147483647' ) {
        echo 'wrong<br>';
}
if( '2147483648' == '2147483646' ) {
        echo 'wrong<br>';
}
if( 2147483648 == 2147483646 ) {
        echo 'wrong<br>';
}
if( strval('2147483648') == strval('2147483646') ) {
        echo 'wrong<br>';
}
if( (string)'2147483648' == (string)'2147483646' ) {
        echo 'wrong<br>';
}

?>


Expected result:
----------------
should be more or less equal to the 32-bit output, except of a higher
number of course.

Actual result:
--------------
64-BIT-Source:
--------------
max
9223372036854775807
intval
9223372036854775807
-9223372036854775808
-9223372036854775808
-9223372036854775808
-9223372036854773760
intval of string
9223372036854775807
9223372036854775807
9223372036854775807
9223372036854775807
9223372036854775807
compares
wrong
wrong
wrong
wrong
wrong


32-BIT-Source:
--------------
max
PHP_INT_MAX
intval
2147483647
-2147483648
-2147483647
-2147483646
-2147483645
intval of string
2147483647
2147483647
2147483647
2147483647
2147483647
compares



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


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

Reply via email to