#37642 [Opn->Bgs]: 3 * 1.35 - 4.05 = 8.881784197E-16 but should be 0.0 (zero) (ALL versions!)
| From: | tony2001@php.net | Date: | Tue, 30 May 2006 09:48:47 +0000 |
| Subject: | #37642 [Opn->Bgs]: 3 * 1.35 - 4.05 = 8.881784197E-16 but should be 0.0 (zero) (ALL versions!) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-97792@lists.php.net to get a copy of this message | ||
ID: 37642
Updated by: tony2001@php.net
Reported By: richard at besite dot nl
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Linux and Windows XP
PHP Version: 5.1.4
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:
------------------------------------------------------------------------
[2006-05-30 09:41:45] richard at besite dot nl
Description:
------------
The calculation of this simple piece goes wrong:
3 * 1.35 - 4.05
Under Linux it gives: 8.881784197E-16
Under Windows it gives: 8.8817841970013E-016
Tested under Linux with: PHP4 4.4.2-1+b1 (Debian package php4 4.4.2-1),
PHP5 5.1.2-1+b1 (Debian package php5 5.1.2-1), PHP5 5.1.2 (Ubutu package
php5 5.1.2-ubuntu3).
Tested under Windows with: PHP4 4.4.2, PHP5 5.1.4, PHP5 snapshot
(5.2.0-dev of 05/30/2006), PHP6 snapshot (6.0.0 dev of 05/30/2006
8:30).
Btw, "3 * 1.36 - 4.08 == 0" returns true like you would expect.
Reproduce code:
---------------
<?php
var_dump( 3 * 1.35 - 4.05 == 0 );
print( 3 * 1.35 - 4.05 );
?>
Expected result:
----------------
bool(true)
0
Actual result:
--------------
bool(false)
8.881784197E-16
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37642&edit=1