NAME

Math::GMP - High speed arbitrary size integer math

SYNOPSIS

use Math::GMP;
my $n = new Math::GMP 2;

$n = $n ** (256*1024);
$n = $n - 1;
print "n is now $n\n";

DESCRIPTION

Math::GMP was designed to be a drop-in replacement both for Math::BigInt and for regular integer arithmetic. Unlike BigInt, though, Math::GMP uses the GNU gmp library for all of its calculations, as opposed to straight Perl functions. This can result in speed improvements.

The downside is that this module requires a C compiler to install -- a small tradeoff in most cases. Also, this module is not 100% compatible to Math::BigInt.

A Math::GMP object can be used just as a normal numeric scalar would be -- the module overloads most of the normal arithmetic operators to provide as seamless an interface as possible. However, if you need a perfect interface, you can do the following:

use Math::GMP qw(:constant);

$n = 2 ** (256 * 1024);
print "n is $n\n";

This would fail without the ':constant' since Perl would use normal doubles to compute the 250,000 bit number, and thereby overflow it into meaninglessness (smaller exponents yield less accurate data due to floating point rounding).

BUGS

As of version 1.0, Math::GMP is mostly compatible with the old Math::BigInt version. It is not a full replacement for the rewritten Math::BigInt versions, though. See the SEE ALSO section on how to achieve to use Math::GMP and retain full compatibility to Math::BigInt.

There are some slight incompatibilities, such as output of positive numbers not being prefixed by a '+' sign. This is intentional.

There are also some things missing, and not everything might work as expected.

SEE ALSO

Math::BigInt has a new interface to use a different library than the default pure Perl implementation. You can use, for instance, Math::GMP with it:

use Math::BigInt lib => 'GMP';

If Math::GMP is not installed, it will fall back to it's own Perl implementation.

See Math::BigInt and Math::BigInt::GMP or Math::BigInt::Pari or Math::BigInt::BitVect.

AUTHOR

Chip Turner <chip@redhat.com>, based on the old Math::BigInt by Mark Biggar and Ilya Zakharevich.