|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76287 bcmod returns incorrect values
Submitted: 2018-04-30 12:33 UTC Modified: 2018-04-30 22:12 UTC
From: kacper dot rowinski at gmail dot com Assigned: cmb (profile)
Status: Closed Package: BC math related
PHP Version: 7.2.5 OS: Linux debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: kacper dot rowinski at gmail dot com
New email:
PHP Version: OS:


 [2018-04-30 12:33 UTC] kacper dot rowinski at gmail dot com
Using bcmod on float return incorrect value

Test script:

$leftOperand = '0.00000000099999';
$modulus = '-0.00056';
$scale =14;

// incorrect :
echo bcmod($leftOperand,$modulus, $scale);

// this how it should work 
// mod(a, b) = a - b * floor(a/b)
echo bcsub(
                floor(bcdiv($leftOperand, $modulus, $scale)),

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-30 12:36 UTC] kacper dot rowinski at gmail dot com
 [2018-04-30 13:54 UTC]
-Status: Open +Status: Analyzed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2018-04-30 13:54 UTC]
bcmod() doesn't use floor() but rather truncates towards zero,
which is also defined this way for POSIX fmod(), so that the
result always has the same sign as the dividend.  Therefore, this
is not a bug, but rather a documentation issue.
 [2018-04-30 17:20 UTC] kacper dot rowinski at gmail dot com
Tx for info I hope this will be soon added to documentation as it's little confusing.
 [2018-04-30 22:11 UTC]
Automatic comment from SVN on behalf of cmb
Log: Fix #76287: bcmod returns incorrect values
 [2018-04-30 22:12 UTC]
-Status: Analyzed +Status: Closed
 [2018-04-30 22:12 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:05 UTC]
Automatic comment on behalf of cmb
Log: Fix #76287: bcmod returns incorrect values
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 03:01:27 2024 UTC