xref: /PHP-8.2/ext/gmp/tests/003.phpt (revision e9f783fc)
1--TEST--
2Check for number base recognition
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7        /* Binary */
8        $test[] = gmp_init("0b10011010010");
9        $test[] = gmp_init("0b10011010010", 2);
10        $test[] = gmp_init("10011010010");
11        $test[] = gmp_init("10011010010", 2);
12
13        /* Octal */
14        $test[] = gmp_init("02322");
15        $test[] = gmp_init("02322", 8);
16        $test[] = gmp_init("2322");
17        $test[] = gmp_init("2322", 8);
18
19        /* Decimal */
20        $test[] = gmp_init("1234");
21        $test[] = gmp_init("1234", 10);
22
23        /* Hexadecimal */
24        $test[] = gmp_init("0x4d2");
25        $test[] = gmp_init("0x4d2", 16);
26        try {
27            $test[] = gmp_init("4d2");
28        } catch (\ValueError $e) {
29            echo $e->getMessage() . \PHP_EOL;
30        }
31        $test[] = gmp_init("4d2", 16);
32
33        for ($i = 0; $i < count($test); $i++) {
34                printf("%s\n", gmp_strval($test[$i]));
35        }
36?>
37--EXPECT--
38gmp_init(): Argument #1 ($num) is not an integer string
391234
401234
4110011010010
421234
431234
441234
452322
461234
471234
481234
491234
501234
511234
52