#34967 [Opn->Bgs]: $y=1.3+0.1>1.4
| From: | tony2001@php.net | Date: | Mon, 24 Oct 2005 10:53:57 +0000 |
| Subject: | #34967 [Opn->Bgs]: $y=1.3+0.1>1.4 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-86974@lists.php.net to get a copy of this message | ||
ID: 34967
Updated by: tony2001@php.net
Reported By: davidyht516 at hotmail dot com
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: windows xp home
PHP Version: 5.0.5
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:
------------------------------------------------------------------------
[2005-10-24 12:53:02] davidyht516 at hotmail dot com
Description:
------------
The erro is: 1.3+0.1>1.4
Reproduce code:
---------------
$y=1.3+0.1;
if($y==1.4){$y-=1.4; echo "yes y-1.4=$y";}
else{$y-=1.4; echo "no y-1.4=$y";}
Expected result:
----------------
The result of the code should be:
yes y-1.4=0
Actual result:
--------------
Actual result is:
no y-1.4=2.2e-12
It happens only when $y=1.3+0.1;
If changing the code to $y=1.2+0.2; then the result is correct.
What is going on here?
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34967&edit=1