#41632 [Opn->Bgs]: float operation error,bad bug!!!!
| From: | johannes@php.net | Date: | Fri, 08 Jun 2007 07:00:55 +0000 |
| Subject: | #41632 [Opn->Bgs]: float operation error,bad bug!!!! | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-113572@lists.php.net to get a copy of this message | ||
ID: 41632
Updated by: johannes@php.net
Reported By: ppyupp at 126 dot com
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: windows linux
PHP Version: 4.4.7
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.
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.
.
Previous Comments:
------------------------------------------------------------------------
[2007-06-08 05:41:20] ppyupp at 126 dot com
Description:
------------
i think is very bad for operation!!
please run the code!
Reproduce code:
---------------
<?php
$t = 1000-882.41;
$t = $t;
$b = 117.59;
var_dump( $t ); // print 117.59
var_dump( $b ); // print 117.59
var_dump( $t*100 ); // print 11759
var_dump( ceil( $t*100 ) ); //print 11760 (error!!!! must be 11759)
if ( $t == $b )
echo '$t == $b';
else
echo '$t != $b';
?>
Expected result:
----------------
float(117.59)
float(117.59)
float(11759)
float(11759)
$t == $b
Actual result:
--------------
float(117.59)
float(117.59)
float(11759)
float(11760)
$t != $b
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41632&edit=1