Bug #76287 [Opn]: bcmod returns incorrect values
| From: | kacper dot rowinski at gmail dot com | Date: | Mon, 30 Apr 2018 12:36:41 +0000 |
| Subject: | Bug #76287 [Opn]: bcmod returns incorrect values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-214990@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76287&edit=1
ID: 76287
User updated by: kacper dot rowinski at gmail dot com
Reported by: kacper dot rowinski at gmail dot com
Summary: bcmod returns incorrect values
Status: Open
Type: Bug
Package: BC math related
Operating System: Linux debian
PHP Version: 7.2.5
Block user comment: N
Private report: N
New Comment:
Prove https://www.wolframalpha.com/input/?i=0.00000000099999+mod+-0.00056
Previous Comments:
------------------------------------------------------------------------
[2018-04-30 12:33:45] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76287&edit=1