php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42835 Multiplication Problem
Submitted: 2007-10-03 05:54 UTC Modified: 2007-10-03 08:11 UTC
From: konrad at fumaco dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.4 OS: Windows
Private report: No CVE-ID: None
 [2007-10-03 05:54 UTC] konrad at fumaco dot com
Description:
------------
$t is supposed to return 0. However, for some reason $x is not the same as $v.

The problem only occurs with this number.

Reproduce code:
---------------
$x = (5.10 * 200);
$v = 1020;
$t = $x - $v;
echo "x = ".$x ."<br>";
echo "v = ".$v ."<br>";
echo "t = ".$t ."<br>";
if($x==$v){
	echo "yes";
} else {
	echo "no";
}

Expected result:
----------------
x = 1020
v = 1020
t = 0
yes

Actual result:
--------------
x = 1020
v = 1020
t = -1.1368683772162E-13
no

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-03 08:11 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: Sun May 12 16:01:35 2024 UTC