PHP :: Doc Bug #76287 :: bcmod returns incorrect values
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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
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

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Wed Aug 15 20:01:25 2018 UTC