Bug 212528 - Math functions problem ( ($x<<$n) | ((pow(2, $n) - 1) & ($x>>(32-$n))) )
Math functions problem ( ($x<<$n) | ((pow(2, $n) - 1) & ($x>>(32-$n))) )
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: php (Show other bugs)
x86_64 Linux
medium Severity medium
: ---
: ---
Assigned To: Joe Orton
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2006-10-27 04:48 EDT by Need Real Name
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-12-11 06:54:05 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2006-10-27 04:48:48 EDT
Description of problem:

I am usin a new RH EL 4 and have a problem with this function. The output is 
not corect and I tryed it also on some other systems and they also have this 
same bug. On my old server with RH 7.3 is answer corect. I think that is 
architecture independent, because do it also on i386 systems.
There is some informations about system :

affected system: 
Red Hat Enterprise Linux ES release 4 (Nahant Update 4)
Linux www.prolux.cz 2.6.9-42.0.3.ELsmp #1 SMP Mon Sep 25 17:24:31 EDT 2006 
x86_64 x86_64 x86_64 GNU/Linux

correct working system:
Red Hat Linux release 7.3 (Valhalla)
Linux prolux.speednet.cz 2.4.20-28.7 #1 Thu Dec 18 11:23:36 EST 2003 i686 

sorce code of php function :

function L($x, $n) {
 return ( ($x<<$n) | ((pow(2, $n) - 1) & ($x>>(32-$n))) );

<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">


<p><font size="4">Test of function:  return ( ($x<<$n) | ((pow(2, $n) - 1) & 
($x>>(32-$n))) );</font></p>
<table border="0" cellspacing="1" width="600">
    <td colspan="2">This is the correct answer:</td>
    <td><font color="#808080">INPUT: </font>-3086048340</td>
    <td><font color="#808080">OUTPUT:</font> 30700937</td>
    <td colspan="2"><hr noshade></td>
    <td colspan="2">Aswer of this function on this server:</td>
    <td><font color="#808080">input: </font>-3086048340</td>
    <td><font color="#808080">output:</font> <? echo L(-3086048340, 5) ?></td>

How reproducible:

Do it all times on affected server

Steps to Reproduce:

1. page on affected server with this source code : 
2. page on corect working server with same souce php code : 

Thank you very much for answer, 

With the best regards

Vasek Valenta
Comment 1 Joe Orton 2006-12-11 06:54:05 EST
Thanks for the report.

The result of "-3086048340 << 5" will overflow signed 32-bit integer arithemetic
(as used internally by PHP) so the output of that function will not be
well-defined for that input.  If you need to reliably manipulate large integers
then the "gmp" extension can be used instead.

Note You need to log in before you can comment on or make changes to this bug.