php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34967 $y=1.3+0.1>1.4
Submitted: 2005-10-24 12:53 UTC Modified: 2005-10-24 12:53 UTC
From: davidyht516 at hotmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.0.5 OS: windows xp home
Private report: No CVE-ID: None
 [2005-10-24 12:53 UTC] 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?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-24 12:53 UTC] tony2001@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC