<?php
GMP gmp_pow ( GMP|int|string $num, int $exponent )
where,
$num = The GMP number base
$exponent = The positive power to raise the base
?>
<?php
// A new result is shown if you run
// this exercise several times
$a01a = [ 0, '0x100', 256, '0400' ];
$a01b = mt_rand(0, 3);
foreach($a01a as $n01a)
{
$p01ab = gmp_pow($n01a, $a01b);
echo 'gmp_pow( ' . $n01a . ', ' . $a01b . ' ) = ' . $p01ab . '<br>';
}
?>
<?php
var_dump(gmp_strval(gmp_pow(2,10)));
echo "<br><br>";
var_dump(gmp_strval(gmp_pow(-2,10)));
echo "<br><br>";
var_dump(gmp_strval(gmp_pow(-2,11)));
echo "<br><br>";
var_dump(gmp_strval(gmp_pow("2",10)));
echo "<br><br>";
var_dump(gmp_strval(gmp_pow("2",0)));
echo "<br><br>";
try {
gmp_pow("2", -1);
} catch (ValueError $exception) {
echo $exception->getMessage() . "<br><br>";
}
var_dump(gmp_strval(gmp_pow("-2",10)));
echo "<br><br>";
var_dump(gmp_strval(gmp_pow(20,10)));
echo "<br><br>";
var_dump(gmp_strval(gmp_pow(50,10)));
echo "<br><br>";
try {
gmp_pow(50,-5);
} catch (ValueError $exception) {
echo $exception->getMessage() . "<br><br>";
}
$n = gmp_init("20");
var_dump(gmp_strval(gmp_pow($n,10)));
echo "<br><br>";
$n = gmp_init("-20");
var_dump(gmp_strval(gmp_pow($n,10)));
echo "<br><br>";
try {
var_dump(gmp_pow(2,array()));
echo "<br><br>";
} catch (TypeError $e) {
echo $e->getMessage(), "<br><br>";
}
try {
var_dump(gmp_pow(array(),10));
echo "<br><br>";
} catch (\TypeError $e) {
echo $e->getMessage() . "<br><br>";
}
?>
<?php
$n = gmp_init(2);
var_dump(pow($n, 10));
echo "<br><br>";
var_dump($n ** 10);
echo "<br><br>";
try {
gmp_pow($n, -10);
} catch (ValueError $exception) {
echo $exception->getMessage() . "<br><br>";
}
try {
$n ** -10;
} catch (ValueError $exception) {
echo $exception->getMessage() . "<br><br>";
}
?>