Doc #53365 [Opn->Csd]: Inaccurate information on floats.
| From: | cataphract@php.net | Date: | Sat, 20 Nov 2010 16:10:20 +0000 |
| Subject: | Doc #53365 [Opn->Csd]: Inaccurate information on floats. | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5564@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53365&edit=1
ID: 53365
Updated by: cataphract@php.net
Reported by: phplists at stanvassilev dot com
Summary: Inaccurate information on floats.
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: -
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cataphract
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2010-11-20 17:10:06] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&revision=305581
Log: - Fixed inaccurate information on floats. Closes bug #53365.
------------------------------------------------------------------------
[2010-11-20 13:24:34] phplists at stanvassilev dot com
Description:
------------
http://php.net/manual/en/language.types.float.php
The "Warning: Floating point precision" box has misleading information
that is
partly based on facts, but not well interpreted to the reader:
Commenting per paragraph and offering replacement:
"It is typical that simple decimal fractions like 0.1 or 0.7 cannot be
converted
into their internal binary counterparts without a small loss of
precision. This
can lead to confusing results: for example, floor((0.1+0.7)*10) will
usually
return 7 instead of the expected 8, since the internal representation
will be
something like 7.9."
This is mostly correct, but I'd change the last sentence to "since the
internal
binary representation of 0.7 is approximately 0.69999..., causing 0.1 +
0.7 to
be approximately 0.79999...."
--
"This is due to the fact that it is impossible to express some fractions
in
decimal notation with a finite number of digits. For instance, 1/3 in
decimal
form becomes 0.3."
This is totally off, and more than one users assumed PHP has *wildly*
inaccurate
floats that would literally represent 1/3 as 0.3 (it's actually
~0.33333333333333331482961625624739) and mixes up periodic decimal
fractions
with problems of converting decimal float to binary float and back. It's
also
redundant with the previous paragraph, I'd remove that sentence.
--
"So never trust floating number results to the last digit, and never
compare
floating point numbers for equality. If higher precision is necessary,
the
arbitrary precision math functions and gmp functions are available."
That's ok.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53365&edit=1