Bug->Doc #76287 [Opn->Ana]: bcmod returns incorrect values
| From: | cmb@php.net | Date: | Mon, 30 Apr 2018 13:54:07 +0000 |
| Subject: | Bug->Doc #76287 [Opn->Ana]: bcmod returns incorrect values | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-15631@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
Updated by: cmb@php.net
Reported by: kacper dot rowinski at gmail dot com
Summary: bcmod returns incorrect values
-Status: Open
+Status: Analyzed
-Type: Bug
+Type: Documentation Problem
Package: BC math related
Operating System: Linux debian
PHP Version: 7.2.5
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2018-04-30 12:36:40] kacper dot rowinski at gmail dot com
Prove https://www.wolframalpha.com/input/?i=0.00000000099999+mod+-0.00056
------------------------------------------------------------------------
[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