php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51480 Error on calculation 100.2 - 100.1 - 0.1
Submitted: 2010-04-05 16:43 UTC Modified: 2010-04-05 16:45 UTC
From: vinilazev at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: Irrelevant 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:
47 + 26 = ?
Subscribe to this entry?

 
 [2010-04-05 16:43 UTC] vinilazev at gmail dot com
Description:
------------
Error on a simple calculation.

The correct result must be zero.

Google and JavaScript are wrong too.

But OpenOffice Calc and GCalcTool (gnome calculator) are correct.

Test script:
---------------
//Try a simple calculation:
$result = 100.2 - 100.1 - 0.1;
echo $result;
//The result is 8.520961714E-15

//And trying (inverting):
$result = 100.2 - 0.1 - 100.1;
echo $result;
//The result is 1.42108547152E-14

Expected result:
----------------
The correct result must be zero!

Actual result:
--------------
8.520961714E-15 and 1.42108547152E-14 respectively.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-05 16:45 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2010-04-05 16:45 UTC] pajoye@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://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC