php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53343 iteration bug with variable assignation
Submitted: 2010-11-18 11:44 UTC Modified: 2010-11-18 11:47 UTC
From: kanea at free dot fr Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.3 OS: w7
Private report: No CVE-ID: None
 [2010-11-18 11:44 UTC] kanea at free dot fr
Description:
------------
iterations give aproximation beetween two val, but . Every time there value are 
the same :

4.38 .. 10

Test script:
---------------
for ($A = 0.8; $A < 5 * 3.1416; $A+=0.01) {
	echo $A."<br />";

}

Expected result:
----------------
0.08
0.09

...

15.68
15.69
15.7

Actual result:
--------------
0.8
0.81

...

4.36
4.37
4.38
4.3899999999999
4.3999999999999

...

9.9899999999998
9.9999999999998
10.01
10.02

...


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-18 11:47 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-11-18 11:47 UTC] rasmus@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-2025 The PHP Group
All rights reserved.
Last updated: Tue Dec 16 22:00:01 2025 UTC