xref: /PHP-8.0/ext/gmp/tests/gmp_abs.phpt (revision 65f14b0d)
1--TEST--
2gmp_abs() basic tests
3--SKIPIF--
4<?php if (!extension_loaded("gmp")) print "skip"; ?>
5--FILE--
6<?php
7
8try {
9    var_dump(gmp_strval(gmp_abs("")));
10} catch (\ValueError $e) {
11    echo $e->getMessage() . \PHP_EOL;
12}
13var_dump(gmp_strval(gmp_abs("0")));
14var_dump(gmp_strval(gmp_abs(0)));
15try {
16    var_dump(gmp_strval(gmp_abs(-111111111111111111111))); // This is a float
17} catch (\TypeError $e) {
18    echo $e->getMessage() . \PHP_EOL;
19}
20var_dump(gmp_strval(gmp_abs("111111111111111111111")));
21var_dump(gmp_strval(gmp_abs("-111111111111111111111")));
22var_dump(gmp_strval(gmp_abs("0000")));
23
24try {
25    // Base 8
26    var_dump(gmp_strval(gmp_abs("09876543")));
27} catch (\ValueError $e) {
28    echo $e->getMessage() . \PHP_EOL;
29}
30try {
31    // Base 8
32    var_dump(gmp_strval(gmp_abs("-099987654")));
33} catch (\ValueError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36
37
38try {
39    var_dump(gmp_abs(array()));
40} catch (\TypeError $e) {
41    echo $e->getMessage() . \PHP_EOL;
42}
43
44echo "Done\n";
45?>
46--EXPECT--
47gmp_abs(): Argument #1 ($num) is not an integer string
48string(1) "0"
49string(1) "0"
50gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, float given
51string(21) "111111111111111111111"
52string(21) "111111111111111111111"
53string(1) "0"
54gmp_abs(): Argument #1 ($num) is not an integer string
55gmp_abs(): Argument #1 ($num) is not an integer string
56gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, array given
57Done
58