php.net |  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
 [2018-04-30 12:33 UTC] kacper dot rowinski at gmail dot com
Description:
------------
Using bcmod on float return incorrect value


Test script:
---------------
<?php

$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(
            $leftOperand,
            bcmul(
                $modulus,
                floor(bcdiv($leftOperand, $modulus, $scale)),
                $scale
            ),
            $scale
        );
*/    

Expected result:
----------------
-0.00055999900001


Actual result:
--------------
0.00000000099999

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-30 12:36 UTC] kacper dot rowinski at gmail dot com
Prove https://www.wolframalpha.com/input/?i=0.00000000099999+mod+-0.00056
 [2018-04-30 13:54 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2018-04-30 13:54 UTC] cmb@php.net
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] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=344895
Log: Fix #76287: bcmod returns incorrect values
 [2018-04-30 22:12 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2018-04-30 22:12 UTC] cmb@php.net
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] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=925efa68ea0fac8767db3c7f85e5464a9c8847a8
Log: Fix #76287: bcmod returns incorrect values
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 03:01:29 2024 UTC