ID: 29547 Updated by: [email protected] Reported By: denbraber dot acbjl at avans dot nl -Status: Feedback +Status: No Feedback Bug Type: Math related Operating System: Solaris / nsapi PHP Version: 4.3.8 New Comment:
No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". Previous Comments: ------------------------------------------------------------------------ [2005-01-11 06:42:10] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php4-STABLE-latest.tar.gz For Windows: http://snaps.php.net/win32/php4-win32-STABLE-latest.zip ------------------------------------------------------------------------ [2004-08-06 14:42:33] denbraber dot acbjl at avans dot nl 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 this bug report at http://bugs.php.net/?id=29547&edit=1
