#25877 [Opn]: >> operator bug for negative LOP

From: Date: Thu, 16 Oct 2003 15:22:49 +0000
Subject: #25877 [Opn]: >> operator bug for negative LOP
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969356616@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 Bug Type: Documentation problem Operating System: Linux Debian, Win32 PHP Version: 4.3.3 New Comment: Yeah, that would probably be a good idea. Maybe just a note that this sort of behaviour is undefined. We should probably check to see how it acts on Windows, too. (I don't have a Win box in front of me at the moment so if anybody could check...) J Previous Comments: ------------------------------------------------------------------------ [2003-10-15 19:55:56] moriyoshi@php.net You may want to see the following thread brought up in the past at the php internals list: http://marc.theaimsgroup.com/?l=php-dev&m=103530736509081&w=2 Anyway, Jay, do you think it is more than enough to add a slight comment on the relevant page that the opeators cannot be used for unsigned operation? I see no reason to bogusify this as I regard this as a documentation problem. ------------------------------------------------------------------------ [2003-10-15 12:57:34] cestmirl at freeside dot sk You're right, it's the same semantics as GCC or Java has for signed int (though I've never experienced this yet as I've raised in Pascal world...). However, in this case, I think it's worth considering to implement Java unsigned shift ops (<<<, >>>) in PHP. Of course, there's no problem to mask out appropriate number of bits from left after making "signed shift" right, but standard operator would be much cleaner solution. ------------------------------------------------------------------------ [2003-10-15 11:54:01] jay@php.net 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 ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/25877 -- Edit this bug report at http://bugs.php.net/?id=25877&edit=1

« previous php.doc (#969356616) next »