For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > July 2004 > #16366 [Opn->Csd]: bit shifting error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #16366 [Opn->Csd]: bit shifting error
vrana@php.net

2004-07-26, 3:56 pm

ID: 16366
Updated by: vrana@php.net
Reported By: adam at adeptsoftware dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: WinXP
PHP Version: 4.1.2
New Comment:

This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.




Previous Comments:
------------------------------------------------------------------------

[2002-04-01 22:43:53] jason@php.net

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

------------------------------------------------------------------------

[2002-03-31 17:53:05] adam at adeptsoftware dot com

Ahh.. It still should produce zero though.

------------------------------------------------------------------------

[2002-03-31 15:32:23] msopacua at idg dot 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 at adeptsoftware dot 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.

------------------------------------------------------------------------

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com