Bug #60548 [Opn->Bgs]: Problema com cálculo
| From: | cataphract@php.net | Date: | Sat, 17 Dec 2011 11:27:44 +0000 |
| Subject: | Bug #60548 [Opn->Bgs]: Problema com cálculo | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-165933@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60548&edit=1
ID: 60548
Updated by: cataphract@php.net
Reported by: ronaldoklais at gmail dot com
Summary: Problema com cálculo
-Status: Open
+Status: Bogus
Type: Bug
Package: Math related
Operating System: Windows XP
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
To be expected. Use multiplication instead ($v = $v_initial + $a * $i), that way the rounding errors
won't accumulate.
Previous Comments:
------------------------------------------------------------------------
[2011-12-16 21:35:06] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60548&edit=1