xref: /PHP-8.0/ext/gmp/tests/gmp_div_qr.phpt (revision 25198277)
1--TEST--
2gmp_div_qr() tests
3--SKIPIF--
4<?php if (!extension_loaded("gmp")) print "skip"; ?>
5--FILE--
6<?php
7
8var_dump(gmp_div_qr(0,1));
9
10try {
11    var_dump(gmp_div_qr(1,0));
12} catch (\DivisionByZeroError $e) {
13    echo $e->getMessage() . \PHP_EOL;
14}
15try {
16    var_dump(gmp_div_qr(gmp_init(1), gmp_init(0)));
17} catch (\DivisionByZeroError $e) {
18    echo $e->getMessage() . \PHP_EOL;
19}
20
21var_dump(gmp_div_qr(12653,23482734));
22try {
23    var_dump(gmp_div_qr(12653,23482734, 10));
24} catch (\ValueError $e) {
25    echo $e->getMessage() . \PHP_EOL;
26}
27var_dump(gmp_div_qr(1123123,123));
28var_dump(gmp_div_qr(1123123,123, 1));
29var_dump(gmp_div_qr(1123123,123, 2));
30var_dump(gmp_div_qr(gmp_init(1123123), gmp_init(123)));
31var_dump(gmp_div_qr(1123123,123, GMP_ROUND_ZERO));
32var_dump(gmp_div_qr(1123123,123, GMP_ROUND_PLUSINF));
33var_dump(gmp_div_qr(1123123,123, GMP_ROUND_MINUSINF));
34
35$fp = fopen(__FILE__, 'r');
36
37try {
38    var_dump(gmp_div_qr($fp, $fp));
39} catch (\TypeError $e) {
40    echo $e->getMessage() . \PHP_EOL;
41}
42try {
43    var_dump(gmp_div_qr(array(), array()));
44} catch (\TypeError $e) {
45    echo $e->getMessage() . \PHP_EOL;
46}
47
48echo "Done\n";
49?>
50--EXPECT--
51array(2) {
52  [0]=>
53  object(GMP)#1 (1) {
54    ["num"]=>
55    string(1) "0"
56  }
57  [1]=>
58  object(GMP)#2 (1) {
59    ["num"]=>
60    string(1) "0"
61  }
62}
63Division by zero
64Division by zero
65array(2) {
66  [0]=>
67  object(GMP)#2 (1) {
68    ["num"]=>
69    string(1) "0"
70  }
71  [1]=>
72  object(GMP)#5 (1) {
73    ["num"]=>
74    string(5) "12653"
75  }
76}
77gmp_div_qr(): Argument #3 ($rounding_mode) must be one of GMP_ROUND_ZERO, GMP_ROUND_PLUSINF, or GMP_ROUND_MINUSINF
78array(2) {
79  [0]=>
80  object(GMP)#4 (1) {
81    ["num"]=>
82    string(4) "9131"
83  }
84  [1]=>
85  object(GMP)#3 (1) {
86    ["num"]=>
87    string(2) "10"
88  }
89}
90array(2) {
91  [0]=>
92  object(GMP)#3 (1) {
93    ["num"]=>
94    string(4) "9132"
95  }
96  [1]=>
97  object(GMP)#4 (1) {
98    ["num"]=>
99    string(4) "-113"
100  }
101}
102array(2) {
103  [0]=>
104  object(GMP)#4 (1) {
105    ["num"]=>
106    string(4) "9131"
107  }
108  [1]=>
109  object(GMP)#3 (1) {
110    ["num"]=>
111    string(2) "10"
112  }
113}
114array(2) {
115  [0]=>
116  object(GMP)#1 (1) {
117    ["num"]=>
118    string(4) "9131"
119  }
120  [1]=>
121  object(GMP)#2 (1) {
122    ["num"]=>
123    string(2) "10"
124  }
125}
126array(2) {
127  [0]=>
128  object(GMP)#2 (1) {
129    ["num"]=>
130    string(4) "9131"
131  }
132  [1]=>
133  object(GMP)#1 (1) {
134    ["num"]=>
135    string(2) "10"
136  }
137}
138array(2) {
139  [0]=>
140  object(GMP)#1 (1) {
141    ["num"]=>
142    string(4) "9132"
143  }
144  [1]=>
145  object(GMP)#2 (1) {
146    ["num"]=>
147    string(4) "-113"
148  }
149}
150array(2) {
151  [0]=>
152  object(GMP)#2 (1) {
153    ["num"]=>
154    string(4) "9131"
155  }
156  [1]=>
157  object(GMP)#1 (1) {
158    ["num"]=>
159    string(2) "10"
160  }
161}
162gmp_div_qr(): Argument #1 ($num1) must be of type GMP|string|int, resource given
163gmp_div_qr(): Argument #1 ($num1) must be of type GMP|string|int, array given
164Done
165