php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69454 Linux
Submitted: 2015-04-15 01:16 UTC Modified: 2015-04-15 01:22 UTC
From: gardist at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.5.23 OS: Linux
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: gardist at gmail dot com
New email:
PHP Version: OS:

 

 [2015-04-15 01:16 UTC] gardist at gmail dot com
Description:
------------
(2.4 - 2.4) must be 0! now it -8.8817841970013E-16

Test script:
---------------
$m = 12;
for($l=0; $l<12; $l++) {
    $m = $m - 2.4;
    echo "<br>".$l.": ".$m;
}



Expected result:
----------------
0: 9.6
1: 7.2
2: 4.8
3: 2.4
4: 0
5: -2.4
6: -4.8
7: -7.2
8: -9.6
9: -12
10: -14.4
11: -16.8

Actual result:
--------------
0: 9.6
1: 7.2
2: 4.8
3: 2.4
4: -8.8817841970013E-16
5: -2.4
6: -4.8
7: -7.2
8: -9.6
9: -12
10: -14.4
11: -16.8

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-15 01:22 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-04-15 01:22 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.

round() the value.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jun 03 04:01:26 2025 UTC