# Strange integer overflows

- Thread: https://externals.io/message/32733
- Original archive: https://news-web.php.net/php.internals/32733
- Started by Maurice on 2007-10-11T08:45:51+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #32733 — Maurice — 2007-10-11T08:45:51+00:00

URL: https://externals.io/message/32733#32733

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
