php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76876 Bug
Submitted: 2018-09-13 06:38 UTC Modified: 2018-09-13 06:39 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: pls-kick-me at yandex dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.2.9 OS: Windows/Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pls-kick-me at yandex dot ru
New email:
PHP Version: OS:

 

 [2018-09-13 06:38 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-13 06:39 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-09-13 06:39 UTC] requinix@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://www.floating-point-gui.de/

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 08:00:02 2026 UTC