php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39425 Specific BUG in DOUBLE mathematics!!!
Submitted: 2006-11-08 08:04 UTC Modified: 2006-11-08 17:00 UTC
From: jvano at read dot sk Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.0 OS: Irrelevant (All)
Private report: No CVE-ID: None
 [2006-11-08 08:04 UTC] jvano at read dot sk
Description:
------------
Problem is in all versions of PHP.

Problem is in basic mathematic operation (+/-) wiht double. When I use simple values and make some basic operation, for example (5.7 - (1.4 + 4.3)).

This problem is in another combinations but not in all.

Reproduce code:
---------------
<?php

echo (5.7 - (1.4 + 4.3));

?>

Expected result:
----------------
In all cases is expected 0(zero). But result is always +/- 8.881784197E-016.

Actual result:
--------------
I think that problem is in representation of double value.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-08 12:06 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.


 [2006-11-08 17:00 UTC] jvano at read dot sk
Thanks for link and explain but don't you think that it is serious problem? Operation is simple and common. The same problem I've found in Java but not in C, C++, C# or Python. 

Some another solution and notice of this problem is on page:
http://www.php.net/manual/en/language.types.float.php#language.types.flo

But my question is, if this can not be solved as well as in other languages (maybe they have similar problem but this concrete they don't)?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 12:00:03 2025 UTC