xref: /PHP-8.2/ext/gmp/tests/gmp_root.phpt (revision e9f783fc)
1--TEST--
2gmp_root() basic tests
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8var_dump(gmp_root(1000, 3));
9var_dump(gmp_root(100, 3));
10var_dump(gmp_root(-100, 3));
11
12var_dump(gmp_root(1000, 4));
13var_dump(gmp_root(100, 4));
14
15try {
16    var_dump(gmp_root(-100, 4));
17} catch (\ValueError $e) {
18    echo $e->getMessage() . \PHP_EOL;
19}
20
21var_dump(gmp_root(0, 3));
22
23try {
24    var_dump(gmp_root(100, 0));
25} catch (\ValueError $e) {
26    echo $e->getMessage() . \PHP_EOL;
27}
28try {
29    var_dump(gmp_root(100, -3));
30} catch (\ValueError $e) {
31    echo $e->getMessage() . \PHP_EOL;
32}
33
34?>
35--EXPECTF--
36object(GMP)#%d (1) {
37  ["num"]=>
38  string(2) "10"
39}
40object(GMP)#%d (1) {
41  ["num"]=>
42  string(1) "4"
43}
44object(GMP)#%d (1) {
45  ["num"]=>
46  string(2) "-4"
47}
48object(GMP)#%d (1) {
49  ["num"]=>
50  string(1) "5"
51}
52object(GMP)#%d (1) {
53  ["num"]=>
54  string(1) "3"
55}
56gmp_root(): Argument #2 ($nth) must be odd if argument #1 ($a) is negative
57object(GMP)#%d (1) {
58  ["num"]=>
59  string(1) "0"
60}
61gmp_root(): Argument #2 ($nth) must be greater than 0
62gmp_root(): Argument #2 ($nth) must be greater than 0
63