note 83790 added to language.types.integer
| From: | eric at osu1 dot php dot net | Date: | Wed, 11 Jun 2008 20:50:14 +0000 |
| Subject: | note 83790 added to language.types.integer | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140362@lists.php.net to get a copy of this message | ||
In response to the comment by me at troyswanson dot net:
-2147483648 falls into the range of 32 bit signed integers yet php treats it as a float. However,
-2147483647-1 is treated as an integer.
The following code demonstrates:
<?php
var_dump(-2147483648); //float(-2147483648)
var_dump(-2147483647 - 1); //int(-2147483648)
?>
This is probably very similar to the MS C bug which also treats -2147483648 as an UNSIGNED because
it thinks it's out of the range of a signed int.
The problem is that the parser does not view "-x" as a single token, but rather as two,
"-" and "x". Since "x" is out of the range of an INT, it is promoted
to float, even though in this unique case, "-x" is in the range of an int.
The best cure is probably to replace "-2147483648" with "0x80000000", as that is
the hexadecimal equivalent of the same number.
Hope that helps explain what's going on
Peace
- Eric / fez
----
Server IP: 64.71.164.2
Probable Submitter: 128.101.8.116
----
Manual Page -- http://www.php.net/manual/en/language.types.integer.php
Edit -- https://master.php.net/note/edit/83790
Del: integrated -- https://master.php.net/note/delete/83790/integrated
Del: useless -- https://master.php.net/note/delete/83790/useless
Del: bad code -- https://master.php.net/note/delete/83790/bad+code
Del: spam -- https://master.php.net/note/delete/83790/spam
Del: non-english -- https://master.php.net/note/delete/83790/non-english
Del: in docs -- https://master.php.net/note/delete/83790/in+docs
Del: other reasons-- https://master.php.net/note/delete/83790
Reject -- https://master.php.net/note/reject/83790
Search -- https://master.php.net/manage/user-notes.php