Bug #71816 [Com]: Assigning literal equivalent of PHP_INT_MIN results in double
Edit report at https://bugs.php.net/bug.php?id=71816&edit=1
ID: 71816
Comment by: danack@php.net
Reported by: patrick at patrickmcdougle dot com
Summary: Assigning literal equivalent of PHP_INT_MIN results
in double
Status: Open
Type: Bug
Package: *General Issues
Operating System: Ubuntu Server 64-bit
PHP Version: 7.0.4
Block user comment: N
Private report: N
New Comment:
Your code is equivalent to doing:
$foo = 9223372036854775808;
$foo = -$foo;
The number on the first line is above PHP_INT_MAX - and so it gets converted to a float....before
being converted to a negative value.
That probably is the correct behaviour, compared to trying to make it resolved at compile time
because having the two lines:
$foo = -9223372036854775808;
$foo = -(9223372036854775808);
resulting in different behaviour would be even more surprising.
Previous Comments:
------------------------------------------------------------------------
[2016-03-14 02:26:10] patrick at patrickmcdougle dot com
Description:
------------
Assigning a variable the PHP_INT_MIN literal to a variable results in a double instead of an
integer. I would expect the min representable integer to remain an integer. See below.
Test script:
---------------
vagrant@vagrant-ubuntu-trusty-64:~$ php -v
PHP 7.0.4-1+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
vagrant@vagrant-ubuntu-trusty-64:~$ php -a
Interactive mode enabled
php > echo PHP_INT_MIN;
-9223372036854775808
php > $foo = -9223372036854775808;
php > print_r($foo);
-9.2233720368548E+18
php > echo gettype($foo);
double
php > $foo = -9223372036854775807;
php > print_r($foo);
-9223372036854775807
php > echo gettype($foo);
integer
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71816&edit=1
Thread (4 messages)