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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
38 - 9 = ?
Subscribe to this entry?

 
 [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: Fri May 03 10:01:31 2024 UTC