php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41106 Simple Expression But Doing Wrong Calculation
Submitted: 2007-04-16 18:03 UTC Modified: 2007-04-16 18:11 UTC
From: neel dot basu dot z at gmail dot net Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.1.6 OS: Windows
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: neel dot basu dot z at gmail dot net
New email:
PHP Version: OS:

 

 [2007-04-16 18:03 UTC] neel dot basu dot z at gmail dot net
Description:
------------
Simple Expression but wrong output.

Reproduce code:
---------------
<?php
$res1 = (1.2-0.1)-1.1;// = 1.1-1.1 -> Evaluates to Zero
$res2 = (2.2-0.1)-2.1;// = 2.1-2.1 -> Also Evaluates to Zero
echo $res1."\t".gettype($res1);
echo "\n";
echo $res2."\t".gettype($res2);
?>

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

Actual result:
--------------
-2.22044604925E-016   double
0   double

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-16 18:05 UTC] neel dot basu dot z at gmail dot net
I am Using php 5.1.6
 [2007-04-16 18:07 UTC] helly@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2007-04-16 18:11 UTC] edink@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: Wed May 01 20:01:29 2024 UTC