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