php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33030 Floating point subtraction : incorrect precision
Submitted: 2005-05-13 22:59 UTC Modified: 2005-05-14 00:08 UTC
From: justandy at lagparty dot org Assigned:
Status: Not a bug Package: Math related
PHP Version: 5CVS-2005-05-13 (dev) OS: XP
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: justandy at lagparty dot org
New email:
PHP Version: OS:

 

 [2005-05-13 22:59 UTC] justandy at lagparty dot org
Description:
------------
PHP 5.0.0 (cli) (built: Jul 13 2004 21:39:58)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.0, Copyright (c) 1998-2004 Zend Technologies

// 

Subtraction for floating point numbers is incorrect. 
I searched the existing bug reports and could not find anything similar. 

Running the same version on LINUX reports the correct value.


Reproduce code:
---------------
<?
//CORRECT: 0.03
echo 1.06 - 1.03; 

//WRONG : 0.029999999999999
echo 6.06 - 6.03;
?>

Expected result:
----------------
0.03

Actual result:
--------------
0.029999999999999

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-14 00:08 UTC] tony2001@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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC