php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13671 error of subtraction
Submitted: 2001-10-15 08:28 UTC Modified: 2001-10-15 08:51 UTC
From: c dot bolerichard at fabi dot fr Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 4.0.5 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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: c dot bolerichard at fabi dot fr
New email:
PHP Version: OS:

 

 [2001-10-15 08:28 UTC] c dot bolerichard at fabi dot fr
These subtractions are false :

$r1 = 1.13 - 1.12;
$r2 = 1.12 - 1.13;

echo "$r1"; /* return : 0.0099999999999998 */
echo "$r2"; /* return : -0.0099999999999998 */

Why ?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-15 08:49 UTC] derick@php.net
They are fine, this is how floating point numbers work. You store ~1.12 and ~1.13, not exactly 1.12 and 1.13.
Not a bug.

Derick
 [2001-10-15 08:51 UTC] hholzgra@php.net
see also the note on floating point precision on
http://www.php.net/manual/en/language.types.float.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 16:01:29 2024 UTC