php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53365 Inaccurate information on floats.
Submitted: 2010-11-20 13:24 UTC Modified: 2010-11-20 17:10 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phplists at stanvassilev dot com Assigned: cataphract (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: -
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phplists at stanvassilev dot com
New email:
PHP Version: OS:

 

 [2010-11-20 13:24 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-20 17:10 UTC] 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 17:10 UTC] cataphract@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cataphract
 [2010-11-20 17:10 UTC] cataphract@php.net
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.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 09:00:01 2026 UTC