php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60548 Problema com cálculo
Submitted: 2011-12-16 21:35 UTC Modified: 2011-12-17 11:27 UTC
From: ronaldoklais at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: Irrelevant OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ronaldoklais at gmail dot com
New email:
PHP Version: OS:

 

 [2011-12-16 21:35 UTC] ronaldoklais at gmail dot com
Description:
------------
Problema com cálculo

Test script:
---------------
<?
$v = 10;
$i = -0.15;

for ($a = 0; $a < 100; $a++) {
	$v += $i;
	echo $v, '<br>';
}

?>

Actual result:
--------------
9.85
9.7
9.55
9.4
9.25
9.1
8.95
8.8
8.65
8.5
8.35
8.2
8.05
7.9
7.75
7.6
7.45
7.3
7.15
7
6.85
6.7
6.55
6.4
6.25
6.1
5.95
5.8
5.65
5.5
5.35
5.2
5.05
4.9
4.75
4.6
4.45
4.3
4.15
4
3.85
3.7
3.55
3.4
3.25
3.1
2.95
2.8
2.65
2.5
2.35
2.2
2.05
1.9
1.75
1.6
1.45
1.3
1.15
0.99999999999999
0.84999999999999
0.69999999999999
0.54999999999999
0.39999999999999
0.24999999999999
0.099999999999988
-0.050000000000012
-0.20000000000001
-0.35000000000001
-0.50000000000001
-0.65000000000001
-0.80000000000001
-0.95000000000001
-1.1
-1.25
-1.4
-1.55
-1.7
-1.85
-2
-2.15
-2.3
-2.45
-2.6
-2.75
-2.9
-3.05
-3.2
-3.35
-3.5
-3.65
-3.8
-3.95
-4.1
-4.25
-4.4
-4.55
-4.7
-4.85
-5


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-17 11:27 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2011-12-17 11:27 UTC] cataphract@php.net
To be expected. Use multiplication instead ($v = $v_initial + $a * $i), that way the rounding errors won't accumulate.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 23:01:31 2024 UTC