Subject: | [PATCH] Add support for probab_prime |
This is a patch to add a binding for GMP's probab_prime() function. It also adds the appropriate tests to the test suite.
--- ./lib/Math/GMP.pm.orig 2004-05-26 12:02:41.554399136 +0300
+++ ./lib/Math/GMP.pm 2004-05-26 12:14:39.682227112 +0300
@@ -151,6 +151,13 @@
return gmp_jacobi(promote(shift), promote(shift));
}
+sub probab_prime {
+ my $x = shift;
+ my $reps = shift;
+ return gmp_probab_prime(promote($x), $reps);
+}
+
+
sub op_add {
my ($n, $m) = @_;
($n, $m) = ($m, $n) if $_[2];
@@ -348,6 +355,15 @@
Calculates the n'th number in the Fibonacci sequence.
+=head2 probab_prime
+
+ $x = Math::GMP->new(7);
+ $x->probab_prime(10);
+
+Probabilistically Determines if the number is a prime. Argument is the number
+of checks to perform. Returns 0 if the number is definitely not a prime,
+1 if it may be, and 2 if it is definitely is a prime.
+
=head1 BUGS
As of version 1.0, Math::GMP is mostly compatible with the old
--- ./t/gmppm.t.orig 2004-05-26 11:42:01.813868344 +0300
+++ ./t/gmppm.t 2004-05-26 11:52:44.919101488 +0300
@@ -49,6 +49,9 @@
$try .= "Math::GMP::intify_gmp(\$x);";
} elsif ($f eq 'new_from_base') {
$try .= "\$x;";
+ } elsif ($f eq 'probab_prime') {
+ my $rets = $args[1];
+ $try .= "Math::GMP::gmp_probab_prime(\$x,$rets);";
} else {
if ( $args[1] =~ /^i([-+]?\d+)$/ ) {
$try .= "\$y = $1;";
@@ -502,3 +505,6 @@
100:10
101:10
99:9
+&probab_prime
+5:10:2
+6:10:0
--- ./GMP.xs.orig 2004-05-26 11:36:45.647932872 +0300
+++ ./GMP.xs 2004-05-26 11:44:53.755729208 +0300
@@ -327,6 +327,17 @@
RETVAL
int
+gmp_probab_prime(m, reps)
+ mpz_t * m
+ int reps
+
+ CODE:
+ RETVAL = mpz_probab_prime_p(*m, reps);
+ OUTPUT:
+ RETVAL
+
+
+int
gmp_jacobi(m, n)
mpz_t * m
mpz_t * n