Bug #76876 [Opn->Nab]: Bug
| From: | requinix@php.net | Date: | Thu, 13 Sep 2018 06:39:40 +0000 |
| Subject: | Bug #76876 [Opn->Nab]: Bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217025@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76876&edit=1
ID: 76876
Updated by: requinix@php.net
Reported by: pls-kick-me at yandex dot ru
Summary: Bug
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Windows/Ubuntu
PHP Version: 7.2.9
Block user comment: N
Private report: N
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://www.floating-point-gui.de/
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2018-09-13 06:38:55] pls-kick-me at yandex dot ru
Description:
------------
Just calculations. At the end of them unexpected result
Test script:
---------------
$total_vote = 2.9;
$points_teaches = [-0.1, -0.1, -0.1, -0.1, -0.1, -0.1, -0.1, -0.1, -0.1, -0.1];
foreach($points_teaches as $point) {
$total_vote += $point;
}
$total_vote += -0.3;
$total_vote += -0.3;
$total_vote += -0.3;
$total_vote += -0.5;
$points_p = [-0.05, -0.05, -0.05, -0.05, -0.05 -0.05, -0.05, -0.05, -0.05, -0.05];
$p = 0.0;
foreach ($points_p as $points) {
$p += $points;
}
$total_vote += $p;
die($total_vote);
Expected result:
----------------
$total_vote == 0
Actual result:
--------------
$total_vote == -1.1102230246252E-15
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76876&edit=1