ID:               34399
 Updated by:       [EMAIL PROTECTED]
 Reported By:      me at lucasoman dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Math related
 Operating System: Fedora Core 3
 PHP Version:      4.4.0
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

In PHP modulus can only be used on integers.


Previous Comments:
------------------------------------------------------------------------

[2005-09-06 23:33:55] me at lucasoman dot com

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 this bug report at http://bugs.php.net/?id=34399&edit=1

Reply via email to