|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53397 Modulo is not accurate with double
Submitted: 2010-11-24 15:12 UTC Modified: 2013-08-06 08:28 UTC
Avg. Score:2.3 ± 0.9
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mryaggi at hotmail dot com Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mryaggi at hotmail dot com
New email:
PHP Version: OS:


 [2010-11-24 15:12 UTC] mryaggi at hotmail dot com
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:

Actual result:


ModuloForDouble (last revision 2010-11-24 14:13 UTC by mryaggi at hotmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-06 08:28 UTC]
-Status: Open +Status: Verified -Package: Variables related +Package: Scripting Engine problem
 [2013-08-06 08:28 UTC]
Test with 5.5.1 32bit. This issue exists still.
 [2013-09-18 21:50 UTC] cmbecker69 at gmx dot de
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] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue May 11 18:01:23 2021 UTC