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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 17:01:28 2025 UTC