xref: /PHP-8.0/ext/gmp/tests/gmp_setbit.phpt (revision 25198277)
1--TEST--
2gmp_setbit() basic tests
3--SKIPIF--
4<?php if (!extension_loaded("gmp")) print "skip"; ?>
5--FILE--
6<?php
7
8$n = gmp_init(-1);
9gmp_setbit($n, 10, -1);
10var_dump(gmp_strval($n));
11
12$n = gmp_init(5);
13try {
14    gmp_setbit($n, -20, 0);
15} catch (\ValueError $e) {
16    echo $e->getMessage() . \PHP_EOL;
17}
18var_dump(gmp_strval($n));
19
20$n = gmp_init(5);
21gmp_setbit($n, 2, 0);
22var_dump(gmp_strval($n));
23
24$n = gmp_init(5);
25gmp_setbit($n, 1, 1);
26var_dump(gmp_strval($n));
27
28$n = gmp_init("100000000000");
29gmp_setbit($n, 23, 1);
30var_dump(gmp_strval($n));
31
32gmp_setbit($n, 23, 0);
33var_dump(gmp_strval($n));
34
35gmp_setbit($n, 3);
36var_dump(gmp_strval($n));
37
38$b = "";
39try {
40    gmp_setbit($b, 23);
41} catch (TypeError $e) {
42    echo $e->getMessage(), "\n";
43}
44$a = array();
45try {
46    gmp_setbit($a, array());
47} catch (TypeError $e) {
48    echo $e->getMessage(), "\n";
49}
50
51echo "Done\n";
52?>
53--EXPECT--
54string(2) "-1"
55gmp_setbit(): Argument #2 ($index) must be greater than or equal to 0
56string(1) "5"
57string(1) "1"
58string(1) "7"
59string(12) "100008388608"
60string(12) "100000000000"
61string(12) "100000000008"
62gmp_setbit(): Argument #1 ($num) must be of type GMP, string given
63gmp_setbit(): Argument #1 ($num) must be of type GMP, array given
64Done
65