From: denbraber dot acbjl at avans dot nl Operating system: Win2000 PHP version: 4.3.8 PHP Bug Type: Math related Bug description: Floatingpoint / locale behaviour strange (need to run script twice)
Description: ------------ When I perform floatingpoint calculations I get really unexpected results. The next three examples should all give 1 as result but they all give 0 as result. echo "floatval \"0.5\"*2=".floatval((2*"0.5"))."<br>"; echo "floatval \"0,5\"*2=".floatval((2*"0,5"))."<br>"; echo "\"0.5\"*2=".(2*"0.5")."<br>"; I found that this could be locale related and so I tried adding just above the previous code: $local=setlocale(LC_ALL,"nld_nld"); echo "<p>Country set to: \"nld_nld\": ".$local."<p>\n"; (or $local=setlocale(LC_NUMERIC,"C"); ) Now when I run the script for the first time after a server start up this will give: Country set to: "nld_nld": Dutch_Netherlands.1252 floatval "0.5"*2=1 "0.5"*2=1 0.5*2=0 Still the last one is incorrect. To make it even weirder, when I hit reload to run the script again it will give: Country set to: "nld_nld": Dutch_Netherlands.1252 floatval "0.5"*2=1 "0.5"*2=1 0.5*2=1 and that is correct!! So every time after a server startup (SunOne webserver with php running as nsapi) I have to run a dummy script to change the locate in order for floatingpoint calculations to be performed correctly in scripts that are run after that. In the past we used older versions of PHP (4.2.x) and those versions did not have this problem. We did run the older versions as CGIBIN under a Netscape Enterprise server but that is not possible anymore with the newer versions so I can't test if it is a result of running PHP as NSAPI now. Is this a know bug and is there a good workaround? Reproduce code: --------------- $local=setlocale(LC_ALL,"nld_nld"); echo "<p>Country set to: \"nld_nld\": ".$local."<p>\n"; echo "floatval \"0.5\"*2=".floatval(2*"0.5")."<br>"; echo "\"0.5\"*2=".(2*"0.5")."<br>"; echo "0.5*2=".(2*0.5)."<br>"; Expected result: ---------------- Country set to: "nld_nld": Dutch_Netherlands.1252 floatval "0.5"*2=1 "0.5"*2=1 0.5*2=1 Actual result: -------------- (without the setlocale:) floatval "0.5"*2=0 "0.5"*2=0 0.5*2=0 or Country set to: "nld_nld": Dutch_Netherlands.1252 floatval "0.5"*2=1 "0.5"*2=1 0.5*2=0 or when teh script is run a secondtime: Country set to: "nld_nld": Dutch_Netherlands.1252 floatval "0.5"*2=1 "0.5"*2=1 0.5*2=1 -- Edit bug report at http://bugs.php.net/?id=29547&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29547&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29547&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=29547&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=29547&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=29547&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=29547&r=needscript Try newer version: http://bugs.php.net/fix.php?id=29547&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=29547&r=support Expected behavior: http://bugs.php.net/fix.php?id=29547&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=29547&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=29547&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=29547&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29547&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=29547&r=dst IIS Stability: http://bugs.php.net/fix.php?id=29547&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=29547&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=29547&r=float