From:             paul dot biggar at gmail dot com
Operating system: Ubuntu dapper (Linux 2.6.15)
PHP version:      Irrelevant
PHP Bug Type:     Documentation problem
Bug description:  Hexadecimal numbers above LONG_INT do convert to floats

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)

-- 
Edit bug report at http://bugs.php.net/?id=36325&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36325&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36325&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36325&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36325&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36325&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36325&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36325&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36325&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36325&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36325&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36325&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36325&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36325&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36325&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36325&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36325&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36325&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36325&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36325&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36325&r=mysqlcfg

Reply via email to