Bug #53397 [Com]: Modulo is not accurate with double
Edit report at https://bugs.php.net/bug.php?id=53397&edit=1
ID: 53397
Comment by: cmbecker69 at gmx dot de
Reported by: mryaggi at hotmail dot com
Summary: Modulo is not accurate with double
Status: Verified
Type: Bug
Package: Scripting Engine problem
Operating System: All
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
The operation a - (floor(a/b)*b) gives not the modulo, but the
remainder. Furthermore it seems the suggested patch does neither
cater for large divisors nor large results.
It *might* be reasonable to stick with the current implementation,
and to state clearly in the documentation[1] that the modulus operator
gives correct results only for integers in the range
[-PHP_INT_MAX - 1, PHP_INT_MAX]. The current wording is somewhat
misleading, IMHO.
[1] <http://www.php.net/manual/en/language.operators.arithmetic.php>
Previous Comments:
------------------------------------------------------------------------
[2013-08-06 08:28:02] yohgaki@php.net
Test with 5.5.1 32bit. This issue exists still.
------------------------------------------------------------------------
[2010-11-24 15:12:40] mryaggi at hotmail dot com
Description:
------------
In C++ :
1290594600000 % 86400000 = 37800000 //correct
But In PHP :
1290594600000 % 86400000 = 30811200 //wrong
However, in PHP :
1290594600000 - (floor(1290594600000/86400000)*86400000) = 37800000 //correct!
Can modulo opertor be implemented this way when left value > PHP_INT_MAX ?
See Patch in attachement
Test script:
---------------
echo 1290594600000 % 86400000;
echo "\n";
echo 1290594600000 - (floor(1290594600000/86400000)*86400000);
Expected result:
----------------
37800000
37800000
Actual result:
--------------
30811200
37800000
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53397&edit=1
Thread (3 messages)