Subject: | 0->bmodpow always return 1 |
In fact, modpow of zero is always zero.
However bmodpow of Math::BigInt::Pari always return 1.
# test script
use Math::BigInt (lib => 'Pari');
my $a = Math::BigInt->bzero();
my $b = new Math::BigInt("12345678901234567890");
my $n = new Math::BigInt("65537");
my $c = $a->copy()->bmodpow($b,$n);
print "$a->modpow($b,$n)=$c\n";
# the result
0->modpow(12345678901234567890,65537)=1
_modpow in Math::BigInt::Pari.pm should be modified as follows:
sub _modpow
{
# modulus of power ($x ** $y) % $z
my ($c,$num,$exp,$mod) = @_;
# in the trivial case,
if (gcmp1($mod)) -> if (gcmp1($mod) || gcmp0($num))
{
$num = PARI(0);
return $num;
}
if (gcmp1($num) || gcmp0($num)) -> if (gcmp1($num))
{
$num = PARI(1);
return $num;
}