Math::Prime::Util::GMP is a set of utilities related to prime numbers, using GMP. This includes primality tests, getting primes in a range, and factoring.
While it certainly can be used directly, the main purpose of this module is for Math::Prime::Util. That module will automatically load this if it is installed, greatly speeding up many of its operations on big numbers.
Inputs and outputs for big numbers are via strings, so you do not need to use a bigint package in your program. However if you do use bigint, Perl will automatically convert input for you, so you do not have to stringify your numbers. This output however will be returned as either Perl scalars or strings. Math::Prime::Util tries to reconvert all strings back into the callers bigint type if possible.
use Math::Prime::Util::GMP ':all';
my $n = "115792089237316195423570985008687907853269984665640564039457584007913129639937";
# This doesn't impact the operation of the module at all, but does let you
# enter big number arguments directly as well as enter (e.g.): 2**2048 + 1.
# is_prob_prime returns 0 for composite, 2 for prime, and 1 for maybe prime
say "$n is ", qw(composite prob_prime def_prime)[is_prob_prime($n)];
# is_prime currently is the same -- a BPSW test is used.
say "$n is prime" if is_prime($n);
# Run a series of Miller-Rabin tests
say "$n is a prime or spsp-2/7/61" if is_strong_pseudoprime($n, 2, 7, 61);
# See if $n is a strong Lucas-Selfridge pseudoprime
say "$n is a prime or slpsp" if is_strong_lucas_pseudoprime($n);
# Return array reference to primes in a range.
my $aref = primes( 10 ** 200, 10 ** 200 + 10000 );
$next = next_prime($n); # next prime > n
$prev = prev_prime($n); # previous prime < n
# Find prime factors of big numbers
@factors = factor(5465610891074107968111136514192945634873647594456118359804135903459867604844945580205745718497);
# Finer control over factoring.
# These stop after finding one factor or exceeding their limit.
@factors = prho_factor($n);
@factors = pbrent_factor($n);
@factors = pminus1_factor($n);
@factors = holf_factor($n);
@factors = squfof_factor($n);