xref: /php-src/ext/bcmath/tests/number/methods/div.phpt (revision fad899e5)
1--TEST--
2BcMath\Number div()
3--EXTENSIONS--
4bcmath
5--FILE--
6<?php
7
8$values1 = ['100.012', '-100.012'];
9
10$values2 = [
11    [100, 'int'],
12    [-30, 'int'],
13    ['-20', 'string'],
14    ['0.01', 'string'],
15    ['-0.40', 'string'],
16    [new BcMath\Number('80.3'), 'object'],
17    [new BcMath\Number('-50.6'), 'object'],
18];
19
20foreach ($values1 as $value1) {
21    $num = new BcMath\Number($value1);
22
23    foreach ($values2 as [$value2, $type]) {
24        echo "{$value1} / {$value2}: {$type}\n";
25        $ret = $num->div($value2);
26        var_dump($ret);
27        echo "\n";
28    }
29}
30?>
31--EXPECT--
32100.012 / 100: int
33object(BcMath\Number)#4 (2) {
34  ["value"]=>
35  string(7) "1.00012"
36  ["scale"]=>
37  int(5)
38}
39
40100.012 / -30: int
41object(BcMath\Number)#5 (2) {
42  ["value"]=>
43  string(16) "-3.3337333333333"
44  ["scale"]=>
45  int(13)
46}
47
48100.012 / -20: string
49object(BcMath\Number)#4 (2) {
50  ["value"]=>
51  string(7) "-5.0006"
52  ["scale"]=>
53  int(4)
54}
55
56100.012 / 0.01: string
57object(BcMath\Number)#5 (2) {
58  ["value"]=>
59  string(9) "10001.200"
60  ["scale"]=>
61  int(3)
62}
63
64100.012 / -0.40: string
65object(BcMath\Number)#4 (2) {
66  ["value"]=>
67  string(8) "-250.030"
68  ["scale"]=>
69  int(3)
70}
71
72100.012 / 80.3: object
73object(BcMath\Number)#5 (2) {
74  ["value"]=>
75  string(15) "1.2454794520547"
76  ["scale"]=>
77  int(13)
78}
79
80100.012 / -50.6: object
81object(BcMath\Number)#4 (2) {
82  ["value"]=>
83  string(16) "-1.9765217391304"
84  ["scale"]=>
85  int(13)
86}
87
88-100.012 / 100: int
89object(BcMath\Number)#3 (2) {
90  ["value"]=>
91  string(8) "-1.00012"
92  ["scale"]=>
93  int(5)
94}
95
96-100.012 / -30: int
97object(BcMath\Number)#4 (2) {
98  ["value"]=>
99  string(15) "3.3337333333333"
100  ["scale"]=>
101  int(13)
102}
103
104-100.012 / -20: string
105object(BcMath\Number)#3 (2) {
106  ["value"]=>
107  string(6) "5.0006"
108  ["scale"]=>
109  int(4)
110}
111
112-100.012 / 0.01: string
113object(BcMath\Number)#4 (2) {
114  ["value"]=>
115  string(10) "-10001.200"
116  ["scale"]=>
117  int(3)
118}
119
120-100.012 / -0.40: string
121object(BcMath\Number)#3 (2) {
122  ["value"]=>
123  string(7) "250.030"
124  ["scale"]=>
125  int(3)
126}
127
128-100.012 / 80.3: object
129object(BcMath\Number)#4 (2) {
130  ["value"]=>
131  string(16) "-1.2454794520547"
132  ["scale"]=>
133  int(13)
134}
135
136-100.012 / -50.6: object
137object(BcMath\Number)#3 (2) {
138  ["value"]=>
139  string(15) "1.9765217391304"
140  ["scale"]=>
141  int(13)
142}
143