php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #36325 Hexadecimal numbers above LONG_INT do convert to floats
Submitted: 2006-02-07 21:55 UTC Modified: 2006-03-07 01:49 UTC
From: paul dot biggar at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Ubuntu dapper (Linux 2.6.15)
Private report: No CVE-ID: None
 [2006-02-07 21:55 UTC] paul dot biggar at gmail dot com
Description:
------------
This is related to bug 32211. The fix specified a documentation fix was required. It seems that this should be fixed in the code base, so that hexadecimal and decimal integers behave identically. Regardless, the documentation doesn't completely describe the behaviour below.

Description:

The manual (http://ie2.php.net/int#language.types.integer.overflow) implies that hexadecimal integers above 2147483647 do not get converted to a float, but rather, are truncated to an int.

In actual fact, only numbers above 0x100000000 get truncated. Hexadecimal numbers between 0x80000000 and 0xffffffff are converted to floats, in the same way as if they had been specified in decimal.



Reproduce code:
---------------
        echo "\nHexdecimal ints near ULONG_MAX(truncated to int(LONG_MAX) after ULONG_MAX)\n";
        echo "0xfffffffd\t= "; var_dump(0xfffffffd);
        echo "0xfffffffe\t= "; var_dump(0xfffffffe);
        echo "0xffffffff\t= "; var_dump(0xffffffff);
        echo "0x100000000\t= "; var_dump(0x100000000);
        echo "0x100000001\t= "; var_dump(0x100000001);
        echo "0x100000002\t= "; var_dump(0x100000002);

        echo "\nDecimal ints near ULONG_MAX(floats as far as the eye can see)\n";
        echo "4294967293\t= "; var_dump(4294967293);
        echo "4294967294\t= "; var_dump(4294967294);
        echo "4294967295\t= "; var_dump(4294967295);
        echo "4294967296\t= "; var_dump(4294967296);
        echo "4294967297\t= "; var_dump(4294967297);
        echo "4294967298\t= "; var_dump(4294967298);


Expected result:
----------------
Hexdecimal ints near ULONG_MAX(truncated to int(LONG_MAX) after ULONG_MAX)
0xfffffffd      = float(4294967293)
0xfffffffe      = float(4294967294)
0xffffffff      = float(4294967295)
0x100000000     = float(4294967296)
0x100000001     = float(4294967297)
0x100000002     = float(4294967298)

Decimal ints near ULONG_MAX(floats as far as the eye can see)
4294967293      = float(4294967293)
4294967294      = float(4294967294)
4294967295      = float(4294967295)
4294967296      = float(4294967296)
4294967297      = float(4294967297)
4294967298      = float(4294967298)

Actual result:
--------------
Hexdecimal ints near ULONG_MAX(truncated to int(LONG_MAX) after ULONG_MAX)
0xfffffffd      = float(4294967293)
0xfffffffe      = float(4294967294)
0xffffffff      = float(4294967295)
0x100000000     = int(2147483647)
0x100000001     = int(2147483647)
0x100000002     = int(2147483647)

Decimal ints near ULONG_MAX(floats as far as the eye can see)
4294967293      = float(4294967293)
4294967294      = float(4294967294)
4294967295      = float(4294967295)
4294967296      = float(4294967296)
4294967297      = float(4294967297)
4294967298      = float(4294967298)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-07 01:49 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 18:01:32 2025 UTC