ID:               29874
 User updated by:  binhqx at mac dot com
 Reported By:      binhqx at mac dot com
 Status:           Open
 Bug Type:         *Math Functions
 Operating System: OS X Server 10.3 (Darwin 7.5.0)
 PHP Version:      Irrelevant
 New Comment:

Original description was cutoff:

Bitwise right shift operator produces incorrect result 
when applied to a double in all version of PHP on OS X.

During a bitwise right shift, the php processor casts 
the operand to a integer.  Most of the time this works
fine, but when the value of the operand is greater the 
32 bits, the variable is chopped to just the last 32
bits. This is the way it should work.
For example: 136586474 >> 10 becomes 133385

Under OS X Server, this casting procedure does not work 
the same way. When value of the operand is greater then 
32
bits, the variable is changed to the largest posable 
value of a integer (2^32). Because all integers are 
signed
this is -1. 8726521066 >> 10 becomes -1

I have tested the the shift operator on Linux using PHP 
4.1.2 - 4.3.4 and it produces the correct results. On OS
X/OS X Server (Darwin 7.5.0) using PHP 4.3.2 - 5.0.1 and 
it produces the incorrect results.

It would appear the bug only exists in the OS X port of 
PHP.

Examples:
Testing OS X Server: http://worldvoicellc.net/
bitshift_test.php

Testing Linux: http://12.160.216.20/altigen/phptest/
bitshift_test.php

Testing code: http://worldvoicellc.net/bitshift_test.txt


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

[2004-08-28 06:27:42] binhqx at mac dot com

Description:
------------
Bitwise right shift operator produces incorrect result 
when applied to a double in all version of PHP on OS X.

During a bitwise right shift, the php processor casts 
the  operand

Reproduce code:
---------------
$operand = 8726521066;
echo ($operand >> 10);

Expected result:
----------------
133385

Actual result:
--------------
-1


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


-- 
Edit this bug report at http://bugs.php.net/?id=29874&edit=1

Reply via email to