Req #64675 [NEW]: Warning about floats for ceil and floor

From: Date: Fri, 19 Apr 2013 11:16:49 +0000
Subject: Req #64675 [NEW]: Warning about floats for ceil and floor
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9748@lists.php.net to get a copy of this message
From:             phpmpan at mpan dot pl
Operating system: 
PHP version:      Irrelevant
Package:          Documentation problem
Bug Type:         Feature/Change Request
Bug description:Warning about floats for ceil and floor

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 bug report at https://bugs.php.net/bug.php?id=64675&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=64675&r=trysnapshot54
Try a snapshot (PHP 5.3):   https://bugs.php.net/fix.php?id=64675&r=trysnapshot53
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=64675&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64675&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64675&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64675&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64675&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64675&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64675&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64675&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=64675&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=64675&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64675&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64675&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64675&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64675&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64675&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64675&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64675&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64675&r=mysqlcfg



Thread (2 messages)

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