#29516 [NEW]: Mathematical calculations give unexpected result
| From: | beckwest22 at yahoo dot com | Date: | Wed, 04 Aug 2004 03:49:10 +0000 |
| Subject: | #29516 [NEW]: Mathematical calculations give unexpected result | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-64057@lists.php.net to get a copy of this message | ||
From: beckwest22 at yahoo dot com
Operating system: Windows XP
PHP version: 5.0.0
PHP Bug Type: Math related
Bug description: Mathematical calculations give unexpected result
Description:
------------
I have been reading that doing some mathematical calculations with floats
and integers in php gives some unexpected results. I am not sure if this
is a bug or not. When I do a combination of division and subtraction with
the number 19, I get unexpected results. I would appreciate any light you
could shine on this subject.
Modules compiled with PHP:
I did not compile any modules with PHP.
The only thing different in my php.ini file is that I uncommented the
extension=php_mysql.dll line in the file.
Reproduce code:
---------------
<?php
$num = 19;
$res = $num/10;
echo $res;
echo "<br>";
$res1 = ($num%10)/10;
echo $res1;
echo "<br>";
$res2 = $res - $res1;
echo $res2;
$final_result = $res2 - 1;
echo "<br>";
echo $final_result;
?>
Expected result:
----------------
This is what I expect from the calculations:
$res = 19/10; // equals 1.9
$res1 = (19%10)/10; // equals 0.9
$res2 = 1.9 - 0.9; // equals 1
$final_result = 1 - 1; // equals 0
expected $final_result to be 0
Actual result:
--------------
$final_result equals -1.11022302463E-016
--
Edit bug report at http://bugs.php.net/?id=29516&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29516&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29516&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=29516&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29516&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29516&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29516&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29516&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29516&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29516&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29516&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29516&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29516&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29516&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29516&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29516&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29516&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29516&r=float