php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31569 Incorrect Values Returned
Submitted: 2005-01-16 12:59 UTC Modified: 2005-02-01 19:02 UTC
From: php at milonic dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4CVS-2005-01-16 OS: Fedora/Linux 9
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at milonic dot com
New email:
PHP Version: OS:

 

 [2005-01-16 12:59 UTC] php at milonic dot com
Description:
------------
Values returned using the following code produce different results (incorrect) in PHP-4.3.10 and PHP-4.3.9 on Fedora Core 3. 

When the same code is executed on a Linux 9 or FreeBSD5.3 machine the values are correct.

Could be a Fedora problem but thought you'd like to take a look.

Reproduce code:
---------------
<?

function fillZeros($a, $b){
	$z = hexdec(80000000);
	if ($z & $a){
		$a = ($a>>1);
		$a &= (~$z);
		$a |= 0x40000000;
		$a = ($a>>($b-1));
	}
	else{
		$a = ($a>>$b);
	}
	return $a;
}



function mixture($a,$b,$c) 
{
	$a -= $b; $a -= $c; $a ^= (fillZeros($c,13));
	$b -= $c; $b -= $a; $b ^= ($a<<8);
	$c -= $a; $c -= $b; $c ^= (fillZeros($b,13));
	$a -= $b; $a -= $c; $a ^= (fillZeros($c,12));
	$b -= $c; $b -= $a; $b ^= ($a<<16);
	$c -= $a; $c -= $b; $c ^= (fillZeros($b,5));
	$a -= $b; $a -= $c; $a ^= (fillZeros($c,3)); 
	$b -= $c; $b -= $a; $b ^= ($a<<10);
	$c -= $a; $c -= $b; $c ^= (fillZeros($b,15));
	return array($a,$b,$c);
}


$test= mixture("11", "22", "33");
echo "$test[0], $test[1], $test[2]\n";

?>

Expected result:
----------------
Should be: 
251066875, -1654377486, -1500734959







Actual result:
--------------
But instead get:
251066875, 1541925888, -402039036

Only happens on Fedora, all other boxes are fine.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-16 14:34 UTC] php at milonic dot com
Sorry but it's still the same even with 4.3.11-DEV

My guess is that this could be a Fedora problem but would like to know either way.

It also seems unrelated to PHP version, happens on all of them both 4 and 5 - It all points to Fedora but just cannot think how.

I'll dig a little deeper and let you know if I find anything

Cheers
Andy
 [2005-01-16 14:45 UTC] php at milonic dot com
Narrowed the problem down to this:

$b=251066875;
$a=-3111919630;
echo $b ^= ($a<<10);

     Fedora 3 echos: 251066875 (wrong)
All other OS's echo: 25768443 (correct)

Maybe it helps?

Cheers
Andy
 [2005-01-16 14:55 UTC] derick@php.net
Did you compile from source? If so, what are the different GCC versions on all machines?
 [2005-01-16 15:19 UTC] php at milonic dot com
Yes from source:
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)

one that I know works fine is:
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

Basically, all machines other than 'Fedora Core 3' are working fine. It's something in FC3 that is wrong, I just can't pinpoint it. 

It's a standard server install by the way, nothing special. Hardware also seems to be unrelated to the problem, tried it on 2 different FC3 servers and get the same result.

Cheers
Andy
 [2005-01-16 15:38 UTC] php at milonic dot com
UPDATE:

Just to confirm that it's also the same with RPM-4.3.9 - so no matter if it's compiled from source or package.

Also (was a long shot) changing precision in php.ini makes no difference either

Cheers
Andy
 [2005-01-16 17:05 UTC] php at milonic dot com
New test case at:
http://www.milonic.com/bugreports/php_fc3.php

Can also confirm that JavaScript will return the same values that older Redhat returns. This is getting weirder by the minute.

Cheers
Andy
 [2005-01-18 13:09 UTC] jorton@php.net
$a=-3111919630;
echo $b ^= ($a<<10);

1. -3111919630 cannot be represented in a 32-bit long, so it's stored in a double
2. "$a << 10" is executed using (long) integer arithmetic, so $a is converted to a long here
3. the Zend macro which converts double to long used to be miscompiled by GCC, but this was fixed in the FC3 gcc.

 [2005-02-01 19:02 UTC] sniper@php.net
Not PHP bug but FC3 gcc bug.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 13:01:30 2024 UTC