ID:               29516
 Updated by:       [EMAIL PROTECTED]
 Reported By:      beckwest22 at yahoo dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Math related
 Operating System: Windows XP
 PHP Version:      5.0.0
 New Comment:

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.
 
Thank you for your interest in PHP.

.


Previous Comments:
------------------------------------------------------------------------

[2004-08-04 05:49:08] beckwest22 at yahoo dot com

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 this bug report at http://bugs.php.net/?id=29516&edit=1

Reply via email to