xref: /PHP-8.1/ext/gmp/tests/gmp_div_q.phpt (revision e9f783fc)
1--TEST--
2gmp_div_q() tests
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8var_dump(gmp_div_q(0,1));
9
10try {
11    var_dump(gmp_div_q(1, 0));
12} catch (\DivisionByZeroError $e) {
13    echo $e->getMessage() . \PHP_EOL;
14}
15
16var_dump(gmp_div_q(12653,23482734));
17try {
18    var_dump(gmp_div_q(12653,23482734, 10));
19} catch (\ValueError $e) {
20    echo $e->getMessage() . \PHP_EOL;
21}
22var_dump(gmp_div_q(1123123,123));
23var_dump(gmp_div_q(1123123,123, 1));
24var_dump(gmp_div_q(1123123,123, 2));
25var_dump(gmp_div_q(1123123,123, GMP_ROUND_ZERO));
26var_dump(gmp_div_q(1123123,123, GMP_ROUND_PLUSINF));
27var_dump(gmp_div_q(1123123,123, GMP_ROUND_MINUSINF));
28
29$fp = fopen(__FILE__, 'r');
30
31try {
32    var_dump(gmp_div_q($fp, $fp));
33} catch (\TypeError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36try {
37    var_dump(gmp_div_q(array(), array()));
38} catch (\TypeError $e) {
39    echo $e->getMessage() . \PHP_EOL;
40}
41
42echo "Done\n";
43?>
44--EXPECT--
45object(GMP)#1 (1) {
46  ["num"]=>
47  string(1) "0"
48}
49Division by zero
50object(GMP)#2 (1) {
51  ["num"]=>
52  string(1) "0"
53}
54gmp_div_q(): Argument #3 ($rounding_mode) must be one of GMP_ROUND_ZERO, GMP_ROUND_PLUSINF, or GMP_ROUND_MINUSINF
55object(GMP)#1 (1) {
56  ["num"]=>
57  string(4) "9131"
58}
59object(GMP)#1 (1) {
60  ["num"]=>
61  string(4) "9132"
62}
63object(GMP)#1 (1) {
64  ["num"]=>
65  string(4) "9131"
66}
67object(GMP)#1 (1) {
68  ["num"]=>
69  string(4) "9131"
70}
71object(GMP)#1 (1) {
72  ["num"]=>
73  string(4) "9132"
74}
75object(GMP)#1 (1) {
76  ["num"]=>
77  string(4) "9131"
78}
79gmp_div_q(): Argument #1 ($num1) must be of type GMP|string|int, resource given
80gmp_div_q(): Argument #1 ($num1) must be of type GMP|string|int, array given
81Done
82