ID: 45278 Updated by: [EMAIL PROTECTED] Reported By: kelfe at gmx dot de -Status: Open +Status: Bogus Bug Type: Math related Operating System: Gentoo64 PHP Version: 5.2.6 New Comment:
Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2008-06-19 10:03:17] kontakt at jandreger dot de I can confirm this bug. Server1: (Intel Celeron 2GHz) ============================================= p123:~ # uname -a Linux p123 2.6.24.7-20080507a #1 SMP Wed May 7 10:10:41 CEST 2008 i686 i686 i386 GNU/Linux p123:~ # php -r 'for($i=0;$i<20;$i++) echo round($i+0.015,2)."\n";' 0.02 1.02 2.02 3.02 4.02 5.02 6.02 7.02 8.02 9.02 10.02 11.02 12.02 13.02 14.02 15.02 16.02 17.02 18.02 19.02 p123:~ # php -v PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan 14 2008 17:07:09) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies Server2: (Dual-Core AMD Opteron(tm) Processor 1216 HE) ============================================================ s456:~ # uname -a Linux s456 2.6.24.7-20080507a #1 SMP Wed May 7 10:13:12 CEST 2008 x86_64 x86_64 x86_64 GNU/Linux s1456:~ # php -v PHP 5.2.0 with Suhosin-Patch 0.9.6.1 (cli) (built: Jul 30 2007 15:36:44) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies with the ionCube PHP Loader v3.1.28, Copyright (c) 2002-2007, by ionCube Ltd. s456:~ # php -r 'for($i=0;$i<20;$i++) echo round($i+0.015,2)."\n";' 0.02 1.01 2.02 3.02 4.01 5.01 6.02 7.02 8.02 9.02 10.02 11.02 12.02 13.02 14.02 15.02 16.02 17.02 18.02 19.02 Notebook( Intel(R) Pentium(R) M processor 2.13GHz) =========================================== asd:~$ php -v PHP 5.2.4-2ubuntu5.1 with Suhosin-Patch 0.9.6.2 (cli) (built: May 9 2008 16:34:16) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies asd:~$ uname -a Linux asd 2.6.24-19-generic #1 SMP Wed Jun 4 16:35:01 UTC 2008 i686 GNU/Linux asd:~$ php -r 'for($i=0;$i<20;$i++) echo round($i+0.015,2)."\n";' 0.02 1.01 2.02 3.02 4.01 5.01 6.02 7.02 8.02 9.02 10.02 11.02 12.02 13.02 14.02 15.02 16.02 17.02 18.02 19.02 ------------------------------------------------------------------------ [2008-06-16 10:20:20] kelfe at gmx dot de Description: ------------ the demo code procduces the expected results on a gentoo 32 bit install (amd 2400+) dev-lang/php-5.2.6-r1 but fails with the actual results on a 64bit install (intel xeon) from the same ebuild the error can reproduced on an older ubuntu PHP 5.2.3 running 64bit as well the loop and sum was only added to reduce the code (could do 20 round of the calculated values as well for the same result) Reproduce code: --------------- php -r 'for($i=0;$i<20;$i++) echo round($i+0.015,2)."\n";' Expected result: ---------------- 0.02 1.02 2.02 3.02 4.02 5.02 6.02 7.02 8.02 9.02 10.02 11.02 12.02 13.02 14.02 15.02 16.02 17.02 18.02 19.02 Actual result: -------------- 0.02 1.01 2.02 3.02 4.01 5.01 6.02 7.02 8.02 9.02 10.02 11.02 12.02 13.02 14.02 15.02 16.02 17.02 18.02 19.02 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45278&edit=1
