#34599 [NEW]: Accuracy of round() function affected by compiler optimizations

From: Date: Thu, 22 Sep 2005 14:04:22 +0000
Subject: #34599 [NEW]: Accuracy of round() function affected by compiler optimizations
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-85446@lists.php.net to get a copy of this message
From: osolo at wndtabs dot com Operating system: Linux PHP version: 4.4.0 PHP Bug Type: *Math Functions Bug description: Accuracy of round() function affected by compiler optimizations Description: ------------ The round() function will return inconsistent results when PHP is compiled under certain Linux distro/CPU/compiler combinations. For example, if when compiling PHP on Gentoo 1.12.0_pre6/cc 3.4.4/Pentium 4, we get: round(0.245,2) => 0.24 Instead of the expected 0.25. I've traced the problem to the PHP_ROUND_WITH_FUZZ macro in ext/standard/math.c. This macro starts out as: #define PHP_ROUND_WITH_FUZZ(val, places) { \ double tmp_val=val, f = pow(10.0, (double) places); \ ... Changing the first line to: volatile double tmp_val=val; double f = pow(10.0, (double) places); \ I suspect the problem is that the optimizer is keeping tmp_val in a floating point register that has a difference precision than a C double. Declaring it volatile keeps it in the variable and makes things more consisntant. -- Edit bug report at http://bugs.php.net/?id=34599&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34599&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34599&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34599&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=34599&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=34599&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=34599&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=34599&r=needscript Try newer version: http://bugs.php.net/fix.php?id=34599&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=34599&r=support Expected behavior: http://bugs.php.net/fix.php?id=34599&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=34599&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=34599&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=34599&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34599&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=34599&r=dst IIS Stability: http://bugs.php.net/fix.php?id=34599&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=34599&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=34599&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=34599&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=34599&r=mysqlcfg

« previous php.bugs (#85446) next »