1--TEST--
2BcMath\Number pow string by operator
3--EXTENSIONS--
4bcmath
5--FILE--
6<?php
7
8$values = [
9    100,
10    '-20',
11    '0.01',
12    '-0.40',
13    3,
14];
15
16$exponents = [
17    2,
18    '3',
19    0,
20    -1,
21    -2,
22];
23
24foreach ($values as $value) {
25    $num1 = new BcMath\Number($value);
26
27    foreach ($exponents as $exponent) {
28        echo "{$value} ** {$exponent}\n";
29        $ret = $num1 ** ((string) $exponent);
30        $ret2 = ((string) $value) ** (new BcMath\Number($exponent));
31        if ($ret->compare($ret2) !== 0) {
32            echo "Result is incorrect.\n";
33        }
34        var_dump($ret);
35        echo "\n";
36    }
37}
38?>
39--EXPECT--
40100 ** 2
41object(BcMath\Number)#2 (2) {
42  ["value"]=>
43  string(5) "10000"
44  ["scale"]=>
45  int(0)
46}
47
48100 ** 3
49object(BcMath\Number)#3 (2) {
50  ["value"]=>
51  string(7) "1000000"
52  ["scale"]=>
53  int(0)
54}
55
56100 ** 0
57object(BcMath\Number)#4 (2) {
58  ["value"]=>
59  string(1) "1"
60  ["scale"]=>
61  int(0)
62}
63
64100 ** -1
65object(BcMath\Number)#5 (2) {
66  ["value"]=>
67  string(4) "0.01"
68  ["scale"]=>
69  int(2)
70}
71
72100 ** -2
73object(BcMath\Number)#2 (2) {
74  ["value"]=>
75  string(6) "0.0001"
76  ["scale"]=>
77  int(4)
78}
79
80-20 ** 2
81object(BcMath\Number)#1 (2) {
82  ["value"]=>
83  string(3) "400"
84  ["scale"]=>
85  int(0)
86}
87
88-20 ** 3
89object(BcMath\Number)#4 (2) {
90  ["value"]=>
91  string(5) "-8000"
92  ["scale"]=>
93  int(0)
94}
95
96-20 ** 0
97object(BcMath\Number)#5 (2) {
98  ["value"]=>
99  string(1) "1"
100  ["scale"]=>
101  int(0)
102}
103
104-20 ** -1
105object(BcMath\Number)#2 (2) {
106  ["value"]=>
107  string(5) "-0.05"
108  ["scale"]=>
109  int(2)
110}
111
112-20 ** -2
113object(BcMath\Number)#1 (2) {
114  ["value"]=>
115  string(6) "0.0025"
116  ["scale"]=>
117  int(4)
118}
119
1200.01 ** 2
121object(BcMath\Number)#3 (2) {
122  ["value"]=>
123  string(6) "0.0001"
124  ["scale"]=>
125  int(4)
126}
127
1280.01 ** 3
129object(BcMath\Number)#5 (2) {
130  ["value"]=>
131  string(8) "0.000001"
132  ["scale"]=>
133  int(6)
134}
135
1360.01 ** 0
137object(BcMath\Number)#2 (2) {
138  ["value"]=>
139  string(1) "1"
140  ["scale"]=>
141  int(0)
142}
143
1440.01 ** -1
145object(BcMath\Number)#1 (2) {
146  ["value"]=>
147  string(6) "100.00"
148  ["scale"]=>
149  int(2)
150}
151
1520.01 ** -2
153object(BcMath\Number)#3 (2) {
154  ["value"]=>
155  string(8) "10000.00"
156  ["scale"]=>
157  int(2)
158}
159
160-0.40 ** 2
161object(BcMath\Number)#4 (2) {
162  ["value"]=>
163  string(6) "0.1600"
164  ["scale"]=>
165  int(4)
166}
167
168-0.40 ** 3
169object(BcMath\Number)#2 (2) {
170  ["value"]=>
171  string(9) "-0.064000"
172  ["scale"]=>
173  int(6)
174}
175
176-0.40 ** 0
177object(BcMath\Number)#1 (2) {
178  ["value"]=>
179  string(1) "1"
180  ["scale"]=>
181  int(0)
182}
183
184-0.40 ** -1
185object(BcMath\Number)#3 (2) {
186  ["value"]=>
187  string(5) "-2.50"
188  ["scale"]=>
189  int(2)
190}
191
192-0.40 ** -2
193object(BcMath\Number)#4 (2) {
194  ["value"]=>
195  string(4) "6.25"
196  ["scale"]=>
197  int(2)
198}
199
2003 ** 2
201object(BcMath\Number)#5 (2) {
202  ["value"]=>
203  string(1) "9"
204  ["scale"]=>
205  int(0)
206}
207
2083 ** 3
209object(BcMath\Number)#1 (2) {
210  ["value"]=>
211  string(2) "27"
212  ["scale"]=>
213  int(0)
214}
215
2163 ** 0
217object(BcMath\Number)#3 (2) {
218  ["value"]=>
219  string(1) "1"
220  ["scale"]=>
221  int(0)
222}
223
2243 ** -1
225object(BcMath\Number)#4 (2) {
226  ["value"]=>
227  string(12) "0.3333333333"
228  ["scale"]=>
229  int(10)
230}
231
2323 ** -2
233object(BcMath\Number)#5 (2) {
234  ["value"]=>
235  string(12) "0.1111111111"
236  ["scale"]=>
237  int(10)
238}
239