xref: /PHP-8.4/ext/gmp/tests/gmp_remroot.phpt (revision e9f783fc)
1--TEST--
2gmp_rootrem() basic tests
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8var_dump(gmp_rootrem(1000, 3));
9var_dump(gmp_rootrem(100, 3));
10var_dump(gmp_rootrem(-100, 3));
11
12var_dump(gmp_rootrem(1000, 4));
13var_dump(gmp_rootrem(100, 4));
14try {
15    var_dump(gmp_rootrem(-100, 4));
16} catch (\ValueError $e) {
17    echo $e->getMessage() . \PHP_EOL;
18}
19
20var_dump(gmp_rootrem(0, 3));
21
22try {
23    var_dump(gmp_rootrem(100, 0));
24} catch (\ValueError $e) {
25    echo $e->getMessage() . \PHP_EOL;
26}
27try {
28    var_dump(gmp_rootrem(100, -3));
29} catch (\ValueError $e) {
30    echo $e->getMessage() . \PHP_EOL;
31}
32
33?>
34--EXPECTF--
35array(2) {
36  [0]=>
37  object(GMP)#%d (1) {
38    ["num"]=>
39    string(2) "10"
40  }
41  [1]=>
42  object(GMP)#%d (1) {
43    ["num"]=>
44    string(1) "0"
45  }
46}
47array(2) {
48  [0]=>
49  object(GMP)#%d (1) {
50    ["num"]=>
51    string(1) "4"
52  }
53  [1]=>
54  object(GMP)#%d (1) {
55    ["num"]=>
56    string(2) "36"
57  }
58}
59array(2) {
60  [0]=>
61  object(GMP)#%d (1) {
62    ["num"]=>
63    string(2) "-4"
64  }
65  [1]=>
66  object(GMP)#%d (1) {
67    ["num"]=>
68    string(3) "-36"
69  }
70}
71array(2) {
72  [0]=>
73  object(GMP)#%d (1) {
74    ["num"]=>
75    string(1) "5"
76  }
77  [1]=>
78  object(GMP)#%d (1) {
79    ["num"]=>
80    string(3) "375"
81  }
82}
83array(2) {
84  [0]=>
85  object(GMP)#%d (1) {
86    ["num"]=>
87    string(1) "3"
88  }
89  [1]=>
90  object(GMP)#%d (1) {
91    ["num"]=>
92    string(2) "19"
93  }
94}
95gmp_rootrem(): Argument #2 ($nth) must be odd if argument #1 ($a) is negative
96array(2) {
97  [0]=>
98  object(GMP)#%d (1) {
99    ["num"]=>
100    string(1) "0"
101  }
102  [1]=>
103  object(GMP)#%d (1) {
104    ["num"]=>
105    string(1) "0"
106  }
107}
108gmp_rootrem(): Argument #2 ($nth) must be greater than or equal to 1
109gmp_rootrem(): Argument #2 ($nth) must be greater than or equal to 1
110