From:             me at lucasoman dot com
Operating system: Fedora Core 3
PHP version:      4.4.0
PHP Bug Type:     Math related
Bug description:  modulus operator truncates decimal operands

Description:
------------
This issue has been brought up before, but not in so many words.

The modulus operator (%) truncates float operands and always returns an
integer result. Some languages behave similarly, some do not. Java, for
one, correctly performs the float calculation.

I see no reason--besides ease of coding or perhaps for the sake of
efficient code--that such an arbitrary limitation would be placed on a
general mathematical operator. Some limitations, like disallowing division
by zero, are not arbitrary; these are required mathematically. However,
restricting modulus to integer operands is not mathematically logical.

You may make the suggestion that I write my own float modulus function
that performs recursive subtractions. However, if your reason for coding
mod as an integer operator is efficiency, writing <i>script</i> code to
perform this calculation--especially on large numbers--is most certainly
not more efficient.

I (humbly) request that you reconsider the way you've coded the mod
operator.

Reproduce code:
---------------
print(4.5 % 2);


Expected result:
----------------
.5

Actual result:
--------------
0

-- 
Edit bug report at http://bugs.php.net/?id=34399&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34399&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34399&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34399&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34399&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34399&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34399&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34399&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34399&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34399&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34399&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=34399&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=34399&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34399&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34399&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34399&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34399&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34399&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34399&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34399&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34399&r=mysqlcfg

Reply via email to