Hi there,

I stumbled upon a very strange behaviour with integer overflows.

On 64-bit systems running a 64-bit operating system (with a PHP compiled for
that operating system) it seems that PHP uses 64-bit integers instead of
32-bit integer (which is the expected behaviour afaik).

On 32-bit system PHP should use 32-bit integer. Thus, the number -17441010873
(> 32 bit) should be "overflowed" to -261141689 (32-bit).

However on all 32-bit Linux system using PHP5 (int)-17441010873 is mapped to
-2147483648 (INT_MIN). On some systems the result in PHP4 is also screwed up.
On Windows XP Pro (32-bit) both PHP5 and PHP4 are working correctly.

Try running the following snippet with PHP4 and PHP5 on your (32-bit) system.

<?php

    $a = -17441010873;
    $b = (int)-17441010873;

    echo "expected on 32-bit systems:\n";
    echo "float(-17441010873)\n";
    echo "int(-261141689)\n";

    echo "\n";

    echo "expected on 64-bit systems:\n";
    echo "int(-17441010873)\n";
    echo "int(-17441010873)\n";

    echo "\n";

    echo "result:\n";

    var_dump($a);
    var_dump($b);

    echo "\n";

?>

For me it looks like a damn bug... is it a bug? Or a "feature"?

Bye,
Maurice

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to