Doc #53208 [Com]: Modulo does not calc right (C99 not mathematical correct)
| From: | fibrefox at dynamicfiles dot de | Date: | Sat, 30 Oct 2010 20:40:12 +0000 |
| Subject: | Doc #53208 [Com]: Modulo does not calc right (C99 not mathematical correct) | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5452@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53208&edit=1
ID: 53208
Comment by: fibrefox at dynamicfiles dot de
Reported by: fibrefox at dynamicfiles dot de
Summary: Modulo does not calc right (C99 not mathematical
correct)
Status: Open
Type: Documentation Problem
Package: *Math Functions
Operating System: any
PHP Version: Irrelevant
Block user comment: N
New Comment:
I see the problem in here, but as i see on the website there are changes
anyway in meanings:
"Backwards incompatible change: Methods with the same name as the last
element of a namespaced class name will no longer be treated as
constructor."
The term "modulus" which the symbol "%" stands for is just wrong here.
To gain the compatibility the documentation should be remade ... or the
"real-modulus" has to be added in the core by offering a new function,
maybe "euclid_mod" or something like that.
It is really important to NOT make programming in some kind of
struggeling through the documentation or the code to find the problem,
as you mentioned, of such a basic operator.
I really think there a lot of coders are wondering about this flaw in
PHP (but it is a sign of C99) and are trying to make workarounds to
"fix" this. Built-in functions should be a little bit faster in here, so
there also will be some kind of performance-boost here.
Anyway, i think the operator should do what he says he would do ...
producing the modulus, and not the remainder.
Previous Comments:
------------------------------------------------------------------------
[2010-10-30 21:27:33] cataphract@php.net
You are of course right, and this merits a mention in the documentation,
but changing the meaning of such a basic operator is a huge BC break.
------------------------------------------------------------------------
[2010-10-30 19:45:59] fibrefox at dynamicfiles dot de
Description:
------------
I found a bug-report that already noted it, but since this is VERY old,
i think it should be re-opened or re-mentioned:
http://bugs.php.net/bug.php?id=20365
Modulo operator DOES NOT calc right.
(-4) mod 10 should be 6, thats the mathematical definition.
modulo is NOT the distance to zero. modulo is NOT the remainder while
division.
the problem is, that the underlying code is written in c/c++, but c99
does NOT have a real modulus, its a remainder-function.
here is a site which describes it:
http://www.alecjacobson.com/weblog/?p=1140
Test script:
---------------
<?php
// euclidean result: 6; php result: -4 .... due to the bug in c++
echo (-4)%10;
?>
Expected result:
----------------
6
Actual result:
--------------
-1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53208&edit=1