Bug #53934 [Ver]: The negative PHP_INT_MAX is incorrectly converted to float
| From: | cmb@php.net | Date: | Tue, 29 May 2018 11:41:16 +0000 |
| Subject: | Bug #53934 [Ver]: The negative PHP_INT_MAX is incorrectly converted to float | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215409@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53934&edit=1
ID: 53934
Updated by: cmb@php.net
Reported by: eriksen dot costa at infranology dot com dot br
Summary: The negative PHP_INT_MAX is incorrectly converted to
float
Status: Verified
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 5.3.5
Block user comment: N
Private report: N
New Comment:
In my opinion, this is not a bug, but rather a documentation
issue. PHP (as many other languages, I believe) does not support
signed literals, but rather only unsigned literals plus the
identity and negation operators.
If we would introduce the notion of signed integer literals, there
would be a difference between
-9223372036854775808 and
0-9223372036854775808 â that's even more confusing.
Previous Comments:
------------------------------------------------------------------------
[2018-05-29 11:25:41] cmb@php.net
Related To: Bug #76385
------------------------------------------------------------------------
[2017-08-02 17:05:36] nikic@php.net
Related To: Bug #75026
------------------------------------------------------------------------
[2015-12-19 23:27:49] ajf at ajf dot me
Since PHP 7 there is PHP_INT_MIN for this purpose, by the way.
------------------------------------------------------------------------
[2014-06-05 15:12:15] ajf at ajf dot me
OK, I found out why this happens. Because the difference between subtraction and negation can't
be known at lexing time ($x = 12-3 vs $x = -3), -9223372036854775808 is actually parsed as
-(9223372036854775808). Since signed integers are asymettrical (max is 9223372036854775807 but min
is -9223372036854775808), 9223372036854775808 overflows and becomes a float. Then the parser sees
-(9.2233720368548E+18) and subtracts it, yielding -9.2233720368548E+18.
I'm not sure how this could be fixed short of parsing numbers at the last minute. Maybe that
would actually reap performance benefits!
------------------------------------------------------------------------
[2014-06-05 14:37:19] ajf at ajf dot me
This issue still exists in master.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=53934
--
Edit this bug report at https://bugs.php.net/bug.php?id=53934&edit=1