jrpruitt Posted February 6, 2008 Share Posted February 6, 2008 Can someone please explain why this simply script comes up with a different answer on CentOS than it does on FreeBSD? $x1=-1639260211; $x2=-1558980842; $y = $x1 + $x2; FreeBSD Result: $y: 1096726243 CentOS Result: $y: -2147483648 FreeBSD 5.4-RELEASE-p9 (KGIX-SMP) #0: PHP Version 5.1.6 CentOS release 5 (Final): PHP 5.2.5 Quote Link to comment https://forums.phpfreaks.com/topic/89714-php-inconsistancy-between-freebsd-and-centos/ Share on other sites More sharing options...
trq Posted February 6, 2008 Share Posted February 6, 2008 I would suggest you have a different precision value in your php.ini's. Quote Link to comment https://forums.phpfreaks.com/topic/89714-php-inconsistancy-between-freebsd-and-centos/#findComment-459729 Share on other sites More sharing options...
sasa Posted February 6, 2008 Share Posted February 6, 2008 FreeBSD use 32-bits integer and CentOS 64-bits Quote Link to comment https://forums.phpfreaks.com/topic/89714-php-inconsistancy-between-freebsd-and-centos/#findComment-459731 Share on other sites More sharing options...
jrpruitt Posted February 6, 2008 Author Share Posted February 6, 2008 Each of these systems have several php.ini files and I'm not sure which one is the correct one to modify. Quote Link to comment https://forums.phpfreaks.com/topic/89714-php-inconsistancy-between-freebsd-and-centos/#findComment-459772 Share on other sites More sharing options...
kenrbnsn Posted February 6, 2008 Share Posted February 6, 2008 Create a file on each system containing <?php phpinfo(); ?> and bring it up on your browser. On the display will be a line indicating where the php.ini file is located that is being used. Ken Quote Link to comment https://forums.phpfreaks.com/topic/89714-php-inconsistancy-between-freebsd-and-centos/#findComment-459778 Share on other sites More sharing options...
jrpruitt Posted February 6, 2008 Author Share Posted February 6, 2008 Ok, I verified both PHP.INI files have precision = 14 and also verified in the phpinfo() that precision is 14. But the above script still comes up with incorrect values. ref: 32bit vs 64bit. This is SUPPOSE to be the 32 bit version of CentOS, but that's not saying someone didn't install the wrong version. It would be a major oversite for such a "portable" language to be affected by something like this, so I'm thinking there must to be some way to force PHP to use 32 bit ints, even on a 64 bit platform. This problem was tracked down after hours of diagnosing why BLOWFISH.PHP was totally incompatible with the other system. Is there some way to GLOBALLY force PHP to use 32 bit integers? (and fix any other issues that might be affected by this)? Quote Link to comment https://forums.phpfreaks.com/topic/89714-php-inconsistancy-between-freebsd-and-centos/#findComment-459852 Share on other sites More sharing options...
jrpruitt Posted February 7, 2008 Author Share Posted February 7, 2008 I've verified it's 32 bit CentOS. I've also discovered the problem is NOT in the addition... it's the %d in the prinf() causing the problem: FreeBSD: y = -1639260211 + -1558980842 echo y: -3198241053 printf y: 1096726243 CentOS: y = -1639260211 + -1558980842 echo y: -3198241053 printf y: -2147483648 Identical Script on both servers: <?php $x1=-1639260211; $x2=-1558980842; $y = $x1+$x2; echo "y = ".$x1." + ".$x2."<br />\n"; echo "echo y: ".$y."<br />\n"; printf("printf y: %14d<br />\n",$y); ?> Note: the "<br />\n" allows this script to display correctly from either web page or CLI. If anyone has a clue as to what might be causing this, please help. Quote Link to comment https://forums.phpfreaks.com/topic/89714-php-inconsistancy-between-freebsd-and-centos/#findComment-460748 Share on other sites More sharing options...
jrpruitt Posted February 7, 2008 Author Share Posted February 7, 2008 Ok, the %d is odd, but it was simply hiding my original problem, which is a problem with the ^ operator: <?php $x1=-1639260211; $x2=-1558980842; $x3=3888969200; $y1 = $x1+$x2; $y2 = ($y1 ^ $x3); $y3 = ($x1+$x2) ^ $x3; echo "y1: ".$y1."<br />\n"; echo "y2: ".$y2."<br />\n"; echo "y3: ".$y3."<br />\n"; ?> FreeBSD: y1: -3198241053 y2: -1500364013 y3: -1500364013 CentOS: y1: -3198241053 y2: 1741485552 y3: 1741485552 I've tested this on SEVEN different Servers: Three servers with Redhat 9 and one with FreeBSD get the y2: -1500364013 result. Two different servers with CentOS and also one Redhat Enterprise get the y2: 1741485552 result. I'm I wrong in thinking PHP is portable? Quote Link to comment https://forums.phpfreaks.com/topic/89714-php-inconsistancy-between-freebsd-and-centos/#findComment-460912 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.