xref: /php-src/ext/bcmath/tests/bcdivmod.phpt (revision f6db576c)
1--TEST--
2bcdivmod() function
3--EXTENSIONS--
4bcmath
5--INI--
6bcmath.scale=0
7--FILE--
8<?php
9require(__DIR__ . "/run_bcmath_tests_function.inc");
10
11$dividends = ["15", "-15", "1", "-9", "14.14", "-16.60", "0.15", "-0.01"];
12$divisors = array_merge($dividends, [
13    "15151324141414.412312232141241",
14    "-132132245132134.1515123765412",
15    "141241241241241248267654747412",
16    "-149143276547656984948124912",
17    "0.1322135476547459213732911312",
18    "-0.123912932193769965476541321",
19]);
20
21$scales = [0, 10];
22foreach ($scales as $scale) {
23    foreach ($dividends as $firstTerm) {
24        foreach ($divisors as $secondTerm) {
25            [$quot, $rem] = bcdivmod($firstTerm, $secondTerm, $scale);
26            $div_ret = bcdiv($firstTerm, $secondTerm, 0);
27            $mod_ret = bcmod($firstTerm, $secondTerm, $scale);
28
29            if (bccomp($quot, $div_ret) !== 0) {
30                echo "Div result is incorrect.\n";
31                var_dump($firstTerm, $secondTerm, $scale, $quot, $rem, $div_ret, $mod_ret);
32                echo "\n";
33            }
34
35            if (bccomp($rem, $mod_ret) !== 0) {
36                echo "Mod result is incorrect.\n";
37                var_dump($firstTerm, $secondTerm, $scale, $quot, $rem, $div_ret, $mod_ret);
38                echo "\n";
39            }
40        }
41    }
42}
43echo 'done!';
44?>
45--EXPECT--
46done!
47