xref: /PHP-8.4/ext/bcmath/tests/bcdiv_by_one.phpt (revision e8fe7e4f)
1--TEST--
2bcdiv() function div by one
3--EXTENSIONS--
4bcmath
5--INI--
6bcmath.scale=0
7--FILE--
8<?php
9$dividend_cases = ['100', '-100'];
10$divisor_cases = ['1.010', '1.01', '1.1', '1', '-1.010', '-1.01', '-1.1', '-1'];
11$scale_cases = [0, 1, 2, 3];
12
13foreach ($scale_cases as $scale) {
14    echo "scale: {$scale}\n";
15    foreach ($divisor_cases as $divisor) {
16        foreach ($dividend_cases as $dividend) {
17            $dividend_label = str_pad($dividend, 4, ' ', STR_PAD_LEFT);
18            $divisor_label = str_pad($divisor, 6, ' ', STR_PAD_LEFT);
19            $quot = bcdiv($dividend, $divisor, $scale);
20            $quot_label = str_pad($quot, $scale + 2 + ($scale ? 1 : 0), ' ', STR_PAD_LEFT);
21            echo $dividend_label, ' / ', $divisor_label, ' = ', $quot_label, "\n";
22        }
23    }
24    echo "\n";
25}
26?>
27--EXPECT--
28scale: 0
29 100 /  1.010 = 99
30-100 /  1.010 = -99
31 100 /   1.01 = 99
32-100 /   1.01 = -99
33 100 /    1.1 = 90
34-100 /    1.1 = -90
35 100 /      1 = 100
36-100 /      1 = -100
37 100 / -1.010 = -99
38-100 / -1.010 = 99
39 100 /  -1.01 = -99
40-100 /  -1.01 = 99
41 100 /   -1.1 = -90
42-100 /   -1.1 = 90
43 100 /     -1 = -100
44-100 /     -1 = 100
45
46scale: 1
47 100 /  1.010 = 99.0
48-100 /  1.010 = -99.0
49 100 /   1.01 = 99.0
50-100 /   1.01 = -99.0
51 100 /    1.1 = 90.9
52-100 /    1.1 = -90.9
53 100 /      1 = 100.0
54-100 /      1 = -100.0
55 100 / -1.010 = -99.0
56-100 / -1.010 = 99.0
57 100 /  -1.01 = -99.0
58-100 /  -1.01 = 99.0
59 100 /   -1.1 = -90.9
60-100 /   -1.1 = 90.9
61 100 /     -1 = -100.0
62-100 /     -1 = 100.0
63
64scale: 2
65 100 /  1.010 = 99.00
66-100 /  1.010 = -99.00
67 100 /   1.01 = 99.00
68-100 /   1.01 = -99.00
69 100 /    1.1 = 90.90
70-100 /    1.1 = -90.90
71 100 /      1 = 100.00
72-100 /      1 = -100.00
73 100 / -1.010 = -99.00
74-100 / -1.010 = 99.00
75 100 /  -1.01 = -99.00
76-100 /  -1.01 = 99.00
77 100 /   -1.1 = -90.90
78-100 /   -1.1 = 90.90
79 100 /     -1 = -100.00
80-100 /     -1 = 100.00
81
82scale: 3
83 100 /  1.010 = 99.009
84-100 /  1.010 = -99.009
85 100 /   1.01 = 99.009
86-100 /   1.01 = -99.009
87 100 /    1.1 = 90.909
88-100 /    1.1 = -90.909
89 100 /      1 = 100.000
90-100 /      1 = -100.000
91 100 / -1.010 = -99.009
92-100 / -1.010 = 99.009
93 100 /  -1.01 = -99.009
94-100 /  -1.01 = 99.009
95 100 /   -1.1 = -90.909
96-100 /   -1.1 = 90.909
97 100 /     -1 = -100.000
98-100 /     -1 = 100.000
99