|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64675 Warning about floats for ceil and floor
Submitted: 2013-04-19 11:16 UTC Modified: 2016-06-14 15:11 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: phpmpan at mpan dot pl Assigned: cmb (profile)
Status: Wont fix Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-04-19 11:16 UTC] phpmpan at mpan dot pl
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:

If examples are required to depict the issue:
    $input = (29 / 100.0) * 100.0;
    echo floor($input); // Outputs: 28, expected: 29
    $input = (7 / 100.0) * 100.0;
    echo ceil($input); // Outputs: 8, expected: 7

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-14 15:11 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2016-06-14 15:11 UTC]
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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 05:01:32 2024 UTC