xref: /PHP-8.4/ext/gmp/tests/gmp_and.phpt (revision e9f783fc)
1--TEST--
2gmp_and() basic tests
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8var_dump(gmp_strval(gmp_and("111111", "2222222")));
9var_dump(gmp_strval(gmp_and(123123, 435234)));
10var_dump(gmp_strval(gmp_and(555, "2342341123")));
11var_dump(gmp_strval(gmp_and(-1, 3333)));
12var_dump(gmp_strval(gmp_and(4545, -20)));
13
14try {
15    var_dump(gmp_strval(gmp_and("test", "no test")));
16} catch (\ValueError $e) {
17    echo $e->getMessage() . \PHP_EOL;
18}
19
20$n = gmp_init("987657876543456");
21var_dump(gmp_strval(gmp_and($n, "34332")));
22$n1 = gmp_init("987657878765436543456");
23var_dump(gmp_strval(gmp_and($n, $n1)));
24
25
26try {
27    var_dump(gmp_and(array(), 1));
28} catch (\TypeError $e) {
29    echo $e->getMessage() . \PHP_EOL;
30}
31try {
32    var_dump(gmp_and(1, array()));
33} catch (\TypeError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36try {
37    var_dump(gmp_and(array(), array()));
38} catch (\TypeError $e) {
39    echo $e->getMessage() . \PHP_EOL;
40}
41
42echo "Done\n";
43?>
44--EXPECT--
45string(6) "106502"
46string(5) "40994"
47string(3) "515"
48string(4) "3333"
49string(4) "4544"
50gmp_and(): Argument #1 ($num1) is not an integer string
51string(4) "1536"
52string(15) "424703623692768"
53gmp_and(): Argument #1 ($num1) must be of type GMP|string|int, array given
54gmp_and(): Argument #2 ($num2) must be of type GMP|string|int, array given
55gmp_and(): Argument #1 ($num1) must be of type GMP|string|int, array given
56Done
57