php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12612 unsigned integer problem
Submitted: 2001-08-07 05:10 UTC Modified: 2001-08-07 17:18 UTC
From: dimon at postmark dot net Assigned: jeroen (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: Windows 2000 Server SP1 5.0.2195
Private report: No CVE-ID: None
 [2001-08-07 05:10 UTC] dimon at postmark dot net
$qq = 0x80000000;
echo $qq;  //2147483648  ok
$qq = 0x80000000 | 0;
echo $qq;  //-2147483648  ???
echo abs($qq);  //-2147483648  ???
echo $qq * -1;  //2147483648  

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-07 16:54 UTC] jeroen@php.net
PHP 4 handles number-constants smartly. I.e., when a number is out of range of integers, it will be auto-converted to float.

var_dump(0x80000000) -> float(2147483648)

While | requires int-arguments, and because it cannot convert float(2147483648) to int, it will take MAX_INT instead.

That abs(MINIMAL_INT) bug, is a bug which I fixed yesterday (coincidence...)

The 0x80000000 | 0; : apparently 

(int) 2147483648.0 => -2147483648
This IS a bug, because it should have been INT_MAX (2147483647)

I'm currently trying to sort that out. By the way, do not put multiple bugs in one report.
 [2001-08-07 17:04 UTC] jeroen@php.net
I wan't really clear on this one: PHP _does not support unsigned ints_

Generally, it support integers from -2147483648 to 2147483647
 [2001-08-07 17:17 UTC] jeroen@php.net
From http://www.docs.intranet.giga/php/language.types.integer.html:

From floating point numbers
When converting from float to integer, the number will be rounded towards zero. 

If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), the result is undefined, since the float hasn't got enough precision to give an exact integer result. No warning, not even a notice will be issued in this case! 

(I should have known, I wrote that myself...)
So there this is "feature", AKA documented bug. Feel free to open a feature request to get that changed...

In the manual it should be better noted in integers -> big number section that it goes for hex too. I'll do that in a minute. 

Status -> Closed (for the abs() bug)

 [2001-08-07 17:18 UTC] jeroen@php.net
This url will also work outside "Jeroen's intranet" ;-)

http://www.php.net/manual/en/language.types.integer.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC