Edit report at http://bugs.php.net/bug.php?id=47424&edit=1
ID: 47424
Comment by: whatrevolution at yahoo dot com
Reported by: d_kelsey at uk dot ibm dot com
Summary: not operator does a C cast to long which is different
to other ops
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Linux 64Bit
PHP Version: 5.2CVS-2009-02-17 (CVS)
New Comment:
Bug OP's test, result:
int 9223372036854775807
int 9223372036854775807
PHP Version 5.2.10-2ubuntu6.4
System Linux 2.6.31-20-generic x86_64
Build Date Jan 6 2010 22:36:47
Server API Apache 2.0 Handler
PHP API 20041225
PHP Extension 20060613
Zend Extension 220060519
Debug Build no
Thread Safety disabled
Zend Memory Manager enabled
Apache/2.2.12 (Ubuntu)
Previous Comments:
------------------------------------------------------------------------
[2009-02-17 14:05:01] d_kelsey at uk dot ibm dot com
Description:
------------
In zend_operators.c the function ZEND_API int bitwise_not_function(..)
handles a double by doing a c cast to a long
"if (op1->type == IS_DOUBLE) {
op1->value.lval = (long) op1->value.dval;
op1->type = IS_LONG;
}"
but all other operators use the zendi_convert_to_long() macro
so not isn't consistent with the other operators.
this can result in an unexpected value as shown in the test case
Reproduce code:
---------------
<?php
define("MAX_64Bit", 9223372036854775807);
$e = (MAX_64Bit + 1);
$f = (int)$e;
var_dump(~(MAX_64Bit + 1));
var_dump(~$f);
?>
Expected result:
----------------
int(-9223372036854775808)
int(-9223372036854775808)
Actual result:
--------------
int(9223372036854775807)
int(-9223372036854775808)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=47424&edit=1