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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC