Doc #53365 [NEW]: Inaccurate information on floats.

From: Date: Sat, 20 Nov 2010 12:24:37 +0000
Subject: Doc #53365 [NEW]: Inaccurate information on floats.
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5563@lists.php.net to get a copy of this message
From: Operating system: - PHP version: Irrelevant Package: Documentation problem Bug Type: Documentation Problem Bug description:Inaccurate information on floats. 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 bug report at http://bugs.php.net/bug.php?id=53365&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53365&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53365&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53365&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53365&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53365&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53365&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53365&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53365&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53365&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53365&r=support Expected behavior: http://bugs.php.net/fix.php?id=53365&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53365&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53365&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53365&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53365&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53365&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53365&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53365&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53365&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53365&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53365&r=mysqlcfg

« previous php.doc.bugs (#5563) next »