Doc #76287 [Ana->Csd]: bcmod returns incorrect values
| From: | cmb@php.net | Date: | Mon, 30 Apr 2018 22:12:04 +0000 |
| Subject: | Doc #76287 [Ana->Csd]: bcmod returns incorrect values | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-15641@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: Analyzed
+Status: Closed
Type: Documentation Problem
Package: BC math related
Operating System: Linux debian
PHP Version: 7.2.5
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2018-04-30 22:11:15] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=344895
Log: Fix #76287: bcmod returns incorrect values
------------------------------------------------------------------------
[2018-04-30 17:20:42] 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 13:54:06] 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 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