php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24365 Result problem with soustractions
Submitted: 2003-06-27 13:22 UTC Modified: 2003-06-27 17:35 UTC
From: jump at worldakt dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.2 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jump at worldakt dot com
New email:
PHP Version: OS:

 

 [2003-06-27 13:22 UTC] jump at worldakt dot com
Description:
------------
It seems that when I soustract something (float) it returns a wrong result.

Reproduce code:
---------------
<?php
echo 290.34 - (142.00 + 148.34);
?>
-5.68434188608E-14

<?php
echo 142.00 + 148.34;
?>
290.34

<?php
echo 290.34 - 290.34;
?>
0

Expected result:
----------------
<?php
echo 290.34 - (142.00 + 148.34);
?>
0

Actual result:
--------------
<?php
echo 290.34 - (142.00 + 148.34);
?>
-5.68434188608E-14

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-27 14:14 UTC] marcot at tabini dot ca
This is not really a bug. It's due to normal fluctuations in the way floating-point numbers are handled by the C libraries. Here's another example of this behaviour:

http://bugs.php.net/bug.php?id=22333

You may also want to check out this bit on IEEE representation of floating-point number to understand why some numbers cannot be represented:

http://www.psc.edu/general/software/packages/ieee/ieee.html
 [2003-06-27 17:35 UTC] sniper@php.net
..

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 21 05:00:02 2025 UTC