PHP 4.0 Bug #5819: Floating-point precison lost only but always for some "magic" numbers
| From: | nightfall at mail dot ru | Date: | Thu, 27 Jul 2000 15:52:23 +0000 |
| Subject: | PHP 4.0 Bug #5819: Floating-point precison lost only but always for some "magic" numbers | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-26493@lists.php.net to get a copy of this message | ||
From: nightfall@mail.ru
Operating system: Win32 (PHP 4.0.1), Linux (PHP 4.0), most likely any other
PHP version: 4.0.1
PHP Bug Type: Other
Bug description: Floating-point precison lost only but always for some "magic" numbers
Look at the following sample:
$a=1.16;
$b=intval($a*100)/100;
It's already classic, but... the result is NOT 1.16 again!
Actually $b=1.15
What??! Try multiplying by 1000, and you will get the right one, 1.16
It's funny, how do you think?
This will work with any "magic" number such as 0.29, 0.58, 1.16, 2.32 e t.c., i.e
0.29*(2^n).
I haven't checked all other possible numbers (joke ;-), but it seems to work the same way
ANYWHERE.
(At least i can guarantee in PHP 4.0 and 4.0.1 for Win32 and Linux, no matter).
I think, it's related to PHP's internal floating-point engine, but... but... you will see
at your own.
-- Helen (nightfall@mail.ru)