xref: /php-src/ext/gmp/tests/gmp_pow_32bits.phpt (revision e0a0e216)
1--TEST--
2gmp_pow() basic tests
3--EXTENSIONS--
4gmp
5--SKIPIF--
6<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?>
7--FILE--
8<?php
9
10var_dump(gmp_strval(gmp_pow(2,10)));
11var_dump(gmp_strval(gmp_pow(-2,10)));
12var_dump(gmp_strval(gmp_pow(-2,11)));
13var_dump(gmp_strval(gmp_pow("2",10)));
14var_dump(gmp_strval(gmp_pow("2",0)));
15try {
16    gmp_pow("2", -1);
17} catch (ValueError $exception) {
18    echo $exception->getMessage() . "\n";
19}
20var_dump(gmp_strval(gmp_pow("-2",10)));
21try {
22    gmp_pow(20,10);
23} catch (ValueError $exception) {
24    echo $exception->getMessage() . "\n";
25}
26try {
27    gmp_pow(50,10);
28} catch (ValueError $exception) {
29    echo $exception->getMessage() . "\n";
30}
31try {
32    gmp_pow(50,-5);
33} catch (ValueError $exception) {
34    echo $exception->getMessage() . "\n";
35}
36try {
37    $n = gmp_init("20");
38    gmp_pow($n,10);
39} catch (ValueError $exception) {
40    echo $exception->getMessage() . "\n";
41}
42try {
43    $n = gmp_init("-20");
44    gmp_pow($n,10);
45} catch (ValueError $exception) {
46    echo $exception->getMessage() . "\n";
47}
48try {
49    var_dump(gmp_pow(2,array()));
50} catch (TypeError $e) {
51    echo $e->getMessage(), "\n";
52}
53
54try {
55    var_dump(gmp_pow(array(),10));
56} catch (\TypeError $e) {
57    echo $e->getMessage() . \PHP_EOL;
58}
59
60echo "Done\n";
61?>
62--EXPECT--
63string(4) "1024"
64string(4) "1024"
65string(5) "-2048"
66string(4) "1024"
67string(1) "1"
68gmp_pow(): Argument #2 ($exponent) must be greater than or equal to 0
69string(4) "1024"
70base and exponent overflow
71base and exponent overflow
72gmp_pow(): Argument #2 ($exponent) must be greater than or equal to 0
73base and exponent overflow
74base and exponent overflow
75gmp_pow(): Argument #2 ($exponent) must be of type int, array given
76gmp_pow(): Argument #1 ($num) must be of type GMP|string|int, array given
77Done
78