xref: /PHP-8.0/ext/gmp/tests/bug50283.phpt (revision e208cb23)
1--TEST--
2Feature Request #50283 (allow base in gmp_strval to use full range: 2 to 62, and -2 to -36)
3--SKIPIF--
4<?php if (!extension_loaded("gmp")) print "skip"; ?>
5--FILE--
6<?php
7$a = gmp_init("0x41682179fbf5");
8printf("Decimal: %s, -36-based: %s\n", gmp_strval($a), gmp_strval($a,-36));
9printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,36));
10try {
11    printf("Decimal: %s, -1-based: %s\n", gmp_strval($a), gmp_strval($a,-1));
12} catch (\ValueError $e) {
13    echo $e->getMessage() . \PHP_EOL;
14}
15try {
16    printf("Decimal: %s, 1-based: %s\n", gmp_strval($a), gmp_strval($a,1));
17} catch (\ValueError $e) {
18    echo $e->getMessage() . \PHP_EOL;
19}
20try {
21    printf("Decimal: %s, -37-based: %s\n", gmp_strval($a), gmp_strval($a,-37));
22} catch (\ValueError $e) {
23    echo $e->getMessage() . \PHP_EOL;
24}
25printf("Decimal: %s, 37-based: %s\n", gmp_strval($a), gmp_strval($a,37));
26printf("Decimal: %s, 62-based: %s\n", gmp_strval($a), gmp_strval($a,62));
27try {
28    printf("Decimal: %s, 63-based: %s\n\n", gmp_strval($a), gmp_strval($a,63));
29} catch (\ValueError $e) {
30    echo $e->getMessage() . \PHP_EOL;
31}
32printf("Base 32 and 62-based: %s\n", gmp_strval(gmp_init("gh82179fbf5", 32), 62));
33?>
34--EXPECT--
35Decimal: 71915494046709, -36-based: PHPISCOOL
36Decimal: 71915494046709, 36-based: phpiscool
37gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
38gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
39gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
40Decimal: 71915494046709, 37-based: KHKATELJF
41Decimal: 71915494046709, 62-based: KQ6yq741
42gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
43Base 32 and 62-based: 1NHkAcdIiD
44