Bug #16366 Updated: bit shifting error

From: Date: Tue, 02 Apr 2002 03:43:53 +0000
Subject: Bug #16366 Updated: bit shifting error
References: 1  Groups: php.bugs php.doc 
Request: Send a blank email to php-bugs+get-3789@lists.php.net to get a copy of this message
ID: 16366 Updated by: jason@php.net Reported By: adam@adeptsoftware.com Status: Open -Bug Type: Math related +Bug Type: Documentation problem Operating System: WinXP PHP Version: 4.1.2 New Comment: This is not really a bug, this is the behavior of a 32 bit system in any language. Run "perl -e 'print 11>>34'" or write a C program which does the same. Since this behavior is common and exists in other languages, the best we could do is document it. -Jason Previous Comments: ------------------------------------------------------------------------ [2002-03-31 17:53:05] adam@adeptsoftware.com Ahh.. It still should produce zero though. ------------------------------------------------------------------------ [2002-03-31 15:32:23] msopacua@idg.nl Actually - the echo(11>>34) issue, is somewhat expected behavior. What happens, is that it returns 11>>2 (34 - 32) - BUT only on a 32-bit system. I just checked at an AIX 64-bit system, and there echo(11>>34) gives 0 And anything above 64-bit is than equal to $int>>($shift % 64). Maybe it should be added to the bitwise operators documentation. <?php print("32 bits test\n"); $int=11; for ($shift=31;$shift<35;$shift++) { print("$shift: "); $check=$int>>$shift; print($check); print("\n\n"); } print("64 bits test\n"); for($shift=63;$shift<67;$shift++) { print("$shift: "); $check=$int>>$shift; print($check); print("\n"); } ?> On a 64-bit system produces: $ php -f test.php 32 bits test 31: 0 32: 0 33: 0 34: 0 64 bits test 63: 0 64: 11 65: 5 66: 2 On a 32-bit system produces: 32 bits test 31: 0 32: 11 33: 5 34: 2 64 bits test 63: 0 64: 11 65: 5 66: 2 ------------------------------------------------------------------------ [2002-03-31 13:42:14] adam@adeptsoftware.com Just a reminder of the original issue: echo (11>>34) produces "2" This is not a documentation problem, unless you want to write that shifting greater than 32 has incorrect results. ------------------------------------------------------------------------ [2002-03-31 13:39:23] daniel@php.net are you sure? there is already a bunch of reports on "floating-point bugs" in PHP. That's why I didn't reopen it. ------------------------------------------------------------------------ [2002-03-31 13:38:51] adam@adeptsoftware.com Well I have 200 groups of 64 on/off's.. I can name the 200 bigint groups but there is no way in hell I am going to name 12,800 bools, not to mention that they would take up 8x more space in the database.. Each group has the same structure - somebody needs to write a DB that uses structures as custom fields. This may be the way they work but this is ancient design - I was surprised as hell when I started learning MySQL and realized that they are still doing things this way. But anyway. Now I am thinking "char binary" since it can be fixed size, but the documentation on PHP's conversions of MySQL is sparse. If someone would like to pursue this in private email please write. The original bug was about bit shifting, which I don't think would involve a conversion to float.. unless PHP is doing something weird. It looks like someone is just not expecting a shift greater than 32. ------------------------------------------------------------------------ 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/16366 -- Edit this bug report at http://bugs.php.net/?id=16366&edit=1

« previous php.bugs (#3789) next »