note 29170 added to language.types.float
| From: | www dot sarioz dot com at rack1 dot php dot net | Date: | Wed, 05 Feb 2003 04:49:03 +0000 |
| Subject: | note 29170 added to language.types.float | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43437@lists.php.net to get a copy of this message | ||
just a comment on something the "Floating point precision" inset, which goes: "This
is related to .... 0.3333333."
While the author probably knows what they are talking about, this loss of precision has nothing to
do with decimal notation, it has to do with representation as a floating-point binary in a finite
register, such as while 0.8 terminates in decimal, it is the repeating 0.110011001100... in binary,
which is truncated. 0.1 and 0.7 are also non-terminating in binary, so they are also truncated, and
the sum of these truncated numbers does not add up to the truncated binary representation of 0.8
(which is why (floor)(0.8*10) yields a different, more intuitive, result). However, since 2 is a
factor of 10, any number that terminates in binary also terminates in decimal.
--
http://www.php.net/manual/en/language.types.float.php
http://master.php.net/manage/user-notes.php?action=edit+29170
http://master.php.net/manage/user-notes.php?action=delete+29170
http://master.php.net/manage/user-notes.php?action=reject+29170