xref: /PHP-8.4/ext/gmp/tests/gmp_sqrtrem.phpt (revision e9f783fc)
1--TEST--
2gmp_sqrtrem() basic tests
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8try {
9    $r = gmp_sqrtrem(-1);
10    var_dump($r);
11} catch (\ValueError $e) {
12    echo $e->getMessage() . \PHP_EOL;
13}
14
15$r = gmp_sqrtrem("0");
16var_dump(gmp_strval($r[0]));
17var_dump(gmp_strval($r[1]));
18
19$r = gmp_sqrtrem(2);
20var_dump(gmp_strval($r[0]));
21var_dump(gmp_strval($r[1]));
22
23$r = gmp_sqrtrem(10);
24var_dump(gmp_strval($r[0]));
25var_dump(gmp_strval($r[1]));
26
27$r = gmp_sqrtrem(7);
28var_dump(gmp_strval($r[0]));
29var_dump(gmp_strval($r[1]));
30
31$r = gmp_sqrtrem(3);
32var_dump(gmp_strval($r[0]));
33var_dump(gmp_strval($r[1]));
34
35$r = gmp_sqrtrem(100000);
36var_dump(gmp_strval($r[0]));
37var_dump(gmp_strval($r[1]));
38
39$r = gmp_sqrtrem("1000000");
40var_dump(gmp_strval($r[0]));
41var_dump(gmp_strval($r[1]));
42
43$r = gmp_sqrtrem("1000001");
44var_dump(gmp_strval($r[0]));
45var_dump(gmp_strval($r[1]));
46
47try {
48    $n = gmp_init(-1);
49    $r = gmp_sqrtrem($n);
50    var_dump($r);
51} catch (\ValueError $e) {
52    echo $e->getMessage() . \PHP_EOL;
53}
54
55$n = gmp_init(1000001);
56$r = gmp_sqrtrem($n);
57var_dump(gmp_strval($r[0]));
58var_dump(gmp_strval($r[1]));
59
60try {
61    var_dump(gmp_sqrtrem(array()));
62} catch (\TypeError $e) {
63    echo $e->getMessage() . \PHP_EOL;
64}
65
66echo "Done\n";
67?>
68--EXPECT--
69gmp_sqrtrem(): Argument #1 ($num) must be greater than or equal to 0
70string(1) "0"
71string(1) "0"
72string(1) "1"
73string(1) "1"
74string(1) "3"
75string(1) "1"
76string(1) "2"
77string(1) "3"
78string(1) "1"
79string(1) "2"
80string(3) "316"
81string(3) "144"
82string(4) "1000"
83string(1) "0"
84string(4) "1000"
85string(1) "1"
86gmp_sqrtrem(): Argument #1 ($num) must be greater than or equal to 0
87string(4) "1000"
88string(1) "1"
89gmp_sqrtrem(): Argument #1 ($num) must be of type GMP|string|int, array given
90Done
91