Skip to content

Commit

Permalink
Basic is_pseudoprime(,) implementation with a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Mar 31, 2009
1 parent 71a17ac commit 9d1c112
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 62 deletions.
4 changes: 1 addition & 3 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Revision history for Math::Primality
Math::Primality Release Summaries

0.01 Date/time
First version, released on an unsuspecting world.

12 changes: 1 addition & 11 deletions README
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
Math::Primality

The README is used to introduce the module and provide instructions on
how to install the module, any machine dependencies it may have (for
example C compilers and installed libraries) and any other information
that should be provided before the module is installed.

A README file is required for CPAN modules since CPAN extracts the README
file from a module distribution so that people browsing the archive
can use it to get an idea of the module's uses. It is usually a good idea
to provide version information here so that people can decide whether
fixes for the module are worth downloading.

Stuff.

INSTALLATION

Expand Down
39 changes: 21 additions & 18 deletions lib/Math/Primality.pm
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package Math::Primality;

use Math::BigInt qw/bgcd/;
use base 'Exporter';
use warnings;
use strict;

=head1 NAME
Math::Primality - The great new Math::Primality!
Math::Primality - Various Primality Algorithms
=head1 VERSION
Expand All @@ -15,37 +17,38 @@ Version 0.01

our $VERSION = '0.01';

our @EXPORT_OK = qw/is_pseudoprime/;

=head1 SYNOPSIS
Quick summary of what the module does.
our %EXPORT_TAGS = ( all => \@EXPORT_OK );

Perhaps a little code snippet.
=head1 SYNOPSIS
use Math::Primality;
use Math::BigInt;
my $foo = Math::Primality->new();
...
my $t1 = is_pseudoprime($x,$base);
my $t2 = is_lucas_pseudoprime($x);
=head1 EXPORT
A list of functions that can be exported. You can delete this section
if you don't export anything, such as for a purely object-oriented module.
=head1 FUNCTIONS
=head2 function1
=cut

sub function1 {
}

=head2 function2
sub is_pseudoprime
{
my ($n, $base) = @_;
# force to BigInts for now
$base ||= 2;
$base = Math::BigInt->new("$base");
$n = Math::BigInt->new("$n");

=cut
# if $n and $base are not coprime, than $base is a factor of $n
$base > 2 && ( Math::BigInt::bgcd($n,$base) != 1 ) && return 0;

sub function2 {
my $m = $n->copy->bdec; # m = n - 1
my $mod = $base->bmodpow($m,$n); # (base**exp) (mod n)
return $mod == 1 ;
}

=head1 AUTHOR
Expand Down
20 changes: 8 additions & 12 deletions t/boilerplate.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,16 @@ sub module_boilerplate_ok {
);
}

TODO: {
local $TODO = "Need to replace the boilerplate text";

not_in_file_ok(README =>
"The README is used..." => qr/The README is used/,
"'version information here'" => qr/to provide version information/,
);
not_in_file_ok(README =>
"The README is used..." => qr/The README is used/,
"'version information here'" => qr/to provide version information/,
);

not_in_file_ok(Changes =>
"placeholder date/time" => qr(Date/time)
);
not_in_file_ok(Changes =>
"placeholder date/time" => qr(Date/time)
);

module_boilerplate_ok('lib/Math/Primality.pm');
module_boilerplate_ok('lib/Math/Primality.pm');


}

18 changes: 0 additions & 18 deletions t/pod-coverage.t

This file was deleted.

0 comments on commit 9d1c112

Please sign in to comment.