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