xref: /PHP-8.2/ext/gmp/tests/gmp_sqrt.phpt (revision e9f783fc)
1--TEST--
2gmp_sqrt() basic tests
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8try {
9    var_dump(gmp_strval(gmp_sqrt(-2)));
10} catch (\ValueError $e) {
11    echo $e->getMessage() . \PHP_EOL;
12}
13try {
14    var_dump(gmp_strval(gmp_sqrt("-2")));
15} catch (\ValueError $e) {
16    echo $e->getMessage() . \PHP_EOL;
17}
18
19var_dump(gmp_strval(gmp_sqrt("0")));
20var_dump(gmp_strval(gmp_sqrt("2")));
21var_dump(gmp_strval(gmp_sqrt("144")));
22
23$n = gmp_init(0);
24var_dump(gmp_strval(gmp_sqrt($n)));
25$n = gmp_init(-144);
26try {
27    var_dump(gmp_strval(gmp_sqrt($n)));
28} catch (\ValueError $e) {
29    echo $e->getMessage() . \PHP_EOL;
30}
31$n = gmp_init(777);
32var_dump(gmp_strval(gmp_sqrt($n)));
33
34try {
35    var_dump(gmp_sqrt(array()));
36} catch (\TypeError $e) {
37    echo $e->getMessage() . \PHP_EOL;
38}
39
40echo "Done\n";
41?>
42--EXPECT--
43gmp_sqrt(): Argument #1 ($num) must be greater than or equal to 0
44gmp_sqrt(): Argument #1 ($num) must be greater than or equal to 0
45string(1) "0"
46string(1) "1"
47string(2) "12"
48string(1) "0"
49gmp_sqrt(): Argument #1 ($num) must be greater than or equal to 0
50string(2) "27"
51gmp_sqrt(): Argument #1 ($num) must be of type GMP|string|int, array given
52Done
53