Bug 212528 - Math functions problem ( ($x<<$n) | ((pow(2, $n) - 1) & ($x>>(32-$n))) )
Summary: Math functions problem ( ($x<<$n) | ((pow(2, $n) - 1) & ($x>>(32-$n))) )
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: php
Version: 4.0
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: ---
: ---
Assignee: Joe Orton
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-10-27 08:48 UTC by Need Real Name
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-12-11 11:54:05 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Need Real Name 2006-10-27 08:48:48 UTC
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
php-4.3.9-3.18


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 
unknown
php-4.1.2-7.3.6


sorce code of php function :

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

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

<body>

<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">
  <tr>
    <td colspan="2">This is the correct answer:</td>
  </tr>
  <tr>
    <td><font color="#808080">INPUT: </font>-3086048340</td>
    <td><font color="#808080">OUTPUT:</font> 30700937</td>
  </tr>
  <tr>
    <td colspan="2"><hr noshade></td>
  </tr>
  <tr>
    <td colspan="2">Aswer of this function on this server:</td>
  </tr>
  <tr>
    <td><font color="#808080">input: </font>-3086048340</td>
    <td><font color="#808080">output:</font> <? echo L(-3086048340, 5) ?></td>
  </tr>
</table>
</body>
</html>


How reproducible:

Do it all times on affected server


Steps to Reproduce:

1. page on affected server with this source code : 
http://www2.prolux.cz/tmp/test.php
2. page on corect working server with same souce php code : 
http://router.prolux.cz/test.php

Thank you very much for answer, 


With the best regards

Vasek Valenta

Comment 1 Joe Orton 2006-12-11 11:54:05 UTC
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.