Bug #67478 [Opn->Nab]: Strange behaviour on casting to integer
| From: | aharvey@php.net | Date: | Thu, 19 Jun 2014 17:49:44 +0000 |
| Subject: | Bug #67478 [Opn->Nab]: Strange behaviour on casting to integer | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186265@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67478&edit=1
ID: 67478
Updated by: aharvey@php.net
Reported by: upyx dot 00 at gmail dot com
Summary: Strange behaviour on casting to integer
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: linux 64
PHP Version: 5.5.13
Block user comment: N
Private report: N
New Comment:
Float -> integer conversion being undefined when the float is beyond PHP_INT_MAX is documented
behaviour: http://php.net/manual/en/language.types.integer.php#language.types.integer.casting.from-float
In practice, this is to do with PHP using signed integers internally, but the official advice is
"don't do that".
Previous Comments:
------------------------------------------------------------------------
[2014-06-19 12:42:41] upyx dot 00 at gmail dot com
Description:
------------
Returns huge negative value when casting float value greater then PHP_INT_MAX to integer.
Test script:
---------------
$ php -r 'var_dump(9223372036854775808);'
double(9.2233720368548E+18)
$ php -r 'var_dump((int)9223372036854775808);'
int(-9223372036854775808)
$ php -r 'var_dump((int)9223372036854775809);'
int(-9223372036854775808)
Expected result:
----------------
double(9.2233720368548E+18)
ERROR (or cut to PHP_INT_MAX, but not negative value!)
ERROR
Actual result:
--------------
double(9.2233720368548E+18)
int(-9223372036854775808)
int(-9223372036854775808)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67478&edit=1