Skip to content

invmod(p, q) can wrongly fail #58

@hvds

Description

@hvds

Hi Dana, how's the release coming along? :)

My code just hit this today under MPU-0.73:

% cat t
use strict;
use warnings;
use Math::GMP;
use Math::Prime::Util qw{ invmod };

my $p = Math::GMP->new(1589) ** 6;
my $q = Math::GMP->new(93) ** 6;
print "p=$p, q=$q\n";

my $i1 = invmod(-$p, $q);
print "i1=@{[ $i1 // '<undef>' ]}\n";

my $i2 = invmod(-$p % $q, $q);
print "i2=@{[ $i2 // '<undef>' ]}\n";

my $prod = (-$p * $i2) % $q;
print +($prod == 1) ? "i2 ok\n" : "i2 not ok\n";
% perl t
p=16096942149150081961, q=646990183449
i1=<undef>
i2=25493952356
i2 ok
% 

I haven't looked into it yet (nor tested it against the latest github code), and it's easy enough to work around, but I assume it shouldn't be doing that - i1 should get the same answer as i2.

Hugo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions