php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41733 float substraction doesn't return 0
Submitted: 2007-06-18 23:48 UTC Modified: 2007-06-24 08:02 UTC
From: mc at glouglou dot net Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 5.2.3 OS: Ubuntu
Private report: No CVE-ID: None
 [2007-06-18 23:48 UTC] mc at glouglou dot net
Description:
------------
Came up with this numbers in a web-app.

I've tested this on various platform (Linux/Windows) and PHP version 4.3.9, 5.1, 5.2.1 and 5.2.3 with default php.ini

Reproduce code:
---------------
<?php echo(859-832.35-26.65) ?>

Expected result:
----------------
0

Actual result:
--------------
-2.13162820728E-14

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-19 05:09 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.


 [2007-06-24 08:02 UTC] mc at glouglou dot net
Ok. 
Thanks for your answer and the reference.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC