|  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
 [2010-04-05 16:43 UTC] vinilazev at gmail dot com
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-05 16:45 UTC]
-Status: Open +Status: Bogus
 [2010-04-05 16:45 UTC]
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:
Thank you for your interest in PHP.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 13:01:30 2024 UTC