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
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: vinilazev at gmail dot com
New email:
PHP Version: OS:

 

 [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-2022 The PHP Group
All rights reserved.
Last updated: Tue Aug 09 21:05:46 2022 UTC