xref: /PHP-8.0/ext/gmp/tests/gmp_pown.phpt (revision 25198277)
1--TEST--
2gmp_powm() basic tests
3--SKIPIF--
4<?php if (!extension_loaded("gmp")) print "skip"; ?>
5--FILE--
6<?php
7
8var_dump(gmp_strval(gmp_powm(0,1,10)));
9var_dump(gmp_strval(gmp_powm(5,1,10)));
10var_dump(gmp_strval(gmp_powm(-5,1,-10)));
11var_dump(gmp_strval(gmp_powm(-5,1,10)));
12var_dump(gmp_strval(gmp_powm(-5,11,10)));
13var_dump(gmp_strval(gmp_powm("77",3,1000)));
14
15$n = gmp_init(11);
16var_dump(gmp_strval(gmp_powm($n,3,1000)));
17$e = gmp_init(7);
18var_dump(gmp_strval(gmp_powm($n,$e,1000)));
19$m = gmp_init(900);
20var_dump(gmp_strval(gmp_powm($n,$e,$m)));
21
22try {
23    var_dump(gmp_powm(5, 11, 0));
24} catch (\DivisionByZeroError $error) {
25    echo $error->getMessage() . \PHP_EOL;
26}
27try {
28    var_dump(gmp_powm(5, "11", gmp_init(0)));
29} catch (\DivisionByZeroError $error) {
30    echo $error->getMessage() . \PHP_EOL;
31}
32
33try {
34    var_dump(gmp_powm(array(),$e,$m));
35} catch (\TypeError $error) {
36    echo $error->getMessage() . \PHP_EOL;
37}
38try {
39    var_dump(gmp_powm($n,array(),$m));
40} catch (\TypeError $error) {
41    echo $error->getMessage() . \PHP_EOL;
42}
43try {
44    var_dump(gmp_powm($n,$error,array()));
45} catch (\TypeError $error) {
46    echo $error->getMessage() . \PHP_EOL;
47}
48try {
49    var_dump(gmp_powm(array(),array(),array()));
50} catch (\TypeError $error) {
51    echo $error->getMessage() . \PHP_EOL;
52}
53
54try {
55    $n = gmp_init("-5");
56    var_dump(gmp_powm(10, $n, 10));
57} catch (\ValueError $error) {
58    echo $error->getMessage() . \PHP_EOL;
59}
60
61$n = gmp_init("0");
62var_dump(gmp_powm(10, $n, 10));
63
64echo "Done\n";
65?>
66--EXPECT--
67string(1) "0"
68string(1) "5"
69string(1) "5"
70string(1) "5"
71string(1) "5"
72string(3) "533"
73string(3) "331"
74string(3) "171"
75string(3) "371"
76Modulo by zero
77Modulo by zero
78gmp_powm(): Argument #1 ($num) must be of type GMP|string|int, array given
79gmp_powm(): Argument #2 ($exponent) must be of type GMP|string|int, array given
80gmp_powm(): Argument #2 ($exponent) must be of type GMP|string|int, TypeError given
81gmp_powm(): Argument #1 ($num) must be of type GMP|string|int, array given
82gmp_powm(): Argument #2 ($exponent) must be greater than or equal to 0
83object(GMP)#6 (1) {
84  ["num"]=>
85  string(1) "1"
86}
87Done
88