#39680 [Opn->Bgs]: Type Casting from float into int
| From: | tony2001@php.net | Date: | Wed, 29 Nov 2006 11:30:22 +0000 |
| Subject: | #39680 [Opn->Bgs]: Type Casting from float into int | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-105677@lists.php.net to get a copy of this message | ||
ID: 39680
Updated by: tony2001@php.net
Reported By: diefans at googlemail dot com
-Status: Open
+Status: Bogus
Bug Type: *Math Functions
Operating System: Linux
PHP Version: 5.2.0
New Comment:
The logic behind this conversion is quite plain:
if (double > LONG_MAX) {
long = (unsigned long) double;
} else {
long = (long) double;
}
You can try to compile a simple program in C and see that the result is
the same.
Previous Comments:
------------------------------------------------------------------------
[2006-11-29 10:19:36] diefans at googlemail dot com
Description:
------------
since version 5.2.0 when I cast a negative float smaller than
-2147483648 into an int all bits are lost and the minimum Integer value
is returned. For positive floats larger than the max integer value all
is fine.
It is not possible to perform bitwise calculations with negative
overflowing values since all usable information is lost.
Reproduce code:
---------------
echo (int) -40000000000;
echo (int) 40000000000;
Expected result:
----------------
-1345294336
1345294336
Actual result:
--------------
-2147483648
1345294336
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39680&edit=1