#27138 [Bgs]: 0.1 and 0.7 evaluate strangely
| From: | kennyt@php.net | Date: | Wed, 04 Feb 2004 02:55:22 +0000 |
| Subject: | #27138 [Bgs]: 0.1 and 0.7 evaluate strangely | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-54362@lists.php.net to get a copy of this message | ||
ID: 27138
Updated by: kennyt@php.net
Reported By: kennyt@php.net
Status: Bogus
Bug Type: Math related
PHP Version: 5CVS-2004-02-03 (dev)
New Comment:
Wow, just five minutes! We're really doing well today!
:)
Previous Comments:
------------------------------------------------------------------------
[2004-02-03 21:53:39] 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.
Thank you for your interest in PHP.
.
------------------------------------------------------------------------
[2004-02-03 21:48:58] kennyt@php.net
Description:
------------
I saw this in a manual note. I don't know if it's
really a problem, but others have agreed it's a bug,
so...
Only when using the floats 0.1 and 0.7 and multiplying
by a number large enough to bring the product of the
two floats' sums above 1 does a strange evaluation
become apparent.
Reproduce code:
---------------
echo (int)((0.1 + 0.7) * 10);
echo intval((0.1 + 0.7) * 10);
echo (int)((0.1 + 0.7) * 20);
echo (int)((0.1 + 0.8) * 20);
echo (int)((0.1 + 0.8) * 10);
Expected result:
----------------
8
8
16
18
9
Actual result:
--------------
7
7
15
18
9
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27138&edit=1