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