Req #64675 [Opn->Wfx]: Warning about floats for ceil and floor
Edit report at https://bugs.php.net/bug.php?id=64675&edit=1
ID: 64675
Updated by: cmb@php.net
Reported by: phpmpan at mpan dot pl
Summary: Warning about floats for ceil and floor
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Documentation problem
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
In my opinion, the floating point precision limitation is not
particularly related to ceil() and floor(), and adding a warning
to *all* functions that accept or return a float value appears to
be distracting. There are already links to the float man page
which has a highly visible (I'd even call it intrusive) warning
regarding precision limits, so I don't see the need to further
document the issue.
Previous Comments:
------------------------------------------------------------------------
[2013-04-19 11:28:02] phpmpan at mpan dot pl
Related To: Bug #23498
------------------------------------------------------------------------
[2013-04-19 11:16:49] phpmpan at mpan dot pl
Description:
------------
As per bug 64674, I request including warning box about floating point numbers for ceil
and floor. I know that floating point numbers data type already warns about that, but
it seems that people are still hit by this issue.
The warning would say something along these lines:
This function operates on floating point numbers. Floating point numbers are only an approximation
of the actual value and may differ a bit from the expected result. It may happen that floating point
values are not integers even if they're expected to be integers if the calculation would be
carried in real numbers domain. See: http://php.net/manual/en/language.types.float.php
If examples are required to depict the issue:
floor:
$input = (29 / 100.0) * 100.0;
echo floor($input); // Outputs: 28, expected: 29
ceil:
$input = (7 / 100.0) * 100.0;
echo ceil($input); // Outputs: 8, expected: 7
Reason
======
Behaviour of these functions is obvious for anyone, who has computer science background, but
countless web developers never touched the theory and know nothing about floating point numbers.
They can be easily affected by misunderstanding of what FP calculations are and they may expect a
result different from what these functions actually return.
Also bug 23498 is still open. I do realize that the idea makes no sense, because for most floating
point arguments both ceil and floor make no sense, but it would be nice to
close the related bug from 2003.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64675&edit=1
Thread (2 messages)