#25877 [Opn->Bgs]: >> operator bug for negative LOP
| From: | jay@php.net | Date: | Wed, 15 Oct 2003 15:54:02 +0000 |
| Subject: | #25877 [Opn->Bgs]: >> operator bug for negative LOP | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969356607@lists.php.net to get a copy of this message | ||
ID: 25877
Updated by: jay@php.net
Reported By: cestmirl at freeside dot sk
-Status: Open
+Status: Bogus
Bug Type: Documentation problem
Operating System: Linux Debian, Win32
PHP Version: 4.3.3
New Comment:
This is expected. (1 << 31) wraps the 32-bit integer
limit, and I believe this behaviour is undefined, at least
in C and C++. If you run the same code in C or C++, the
result is the same as what you're experiencing.
J
Previous Comments:
------------------------------------------------------------------------
[2003-10-15 08:00:22] moriyoshi@php.net
Heh, who told me that C supports '>>>' operator... there's no such
operator in that language.
------------------------------------------------------------------------
[2003-10-15 07:56:56] moriyoshi@php.net
Since PHP doesn't support unsigned shift operations that are
represented by '<<<' or '>>>' in the C language, bit shift
operations
are done in "sign-respectful" manner, where the most significant bit
will never be changed. This is expected behaviour, but not documented
yet.
------------------------------------------------------------------------
[2003-10-15 07:40:14] cestmirl at freeside dot sk
Description:
------------
Bitwise shift right operator returns negative result (most significant
bit set) for negative input (left operand).
Following assert fails (though should NOT)
assert((1 << 31 >> 31) == 1);
Reproduce code:
---------------
assert((1 << 31 >> 31) == 1);
Actual result:
--------------
assertion failed
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=25877&edit=1