GMP logo Welcome to the GNU MP web pages! Here you can find information about the GMP library, some important patches, and an outline of planned future developments. You can also find the manual and some useful diagrams here.

GMP 3.1.1 has been released (2000-10-10)
What's new in GMP 3.1?
What's new in GMP 3.0?

What is GMP?
GMP function classes
GMP documentation
Download the latest release of GMP
Improving GMP
Discussing GMP
Frequently asked questions
Status of the current release
Projects using GMP
Try GMP!
Future releases.


What is GMP?

GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers. There is no limit to the precision except the ones implied by the available memory in the machine GMP runs on. GMP has a rich set of functions, and the functions have a regular interface.

GMP is designed to be as fast as possible, both for small operands and for huge operands. The speed is achieved by using fullwords as the basic arithmetic type, by using fast algorithms, with carefully optimized assembly code for the most common inner loops for a lot of CPUs, and by a general emphasis on speed (instead of simplicity or elegance).

GMP is believed to be faster than any other similar library. The advantage for GMP increases with the operand sizes for certain operations, since GMP in many cases has asymptotically faster algorithms.

GMP is distributed under the GNU Lesser General Public License. For more information about the GNU project, please see the official GNU web site.

GMP function classes

There are five classes of functions in GMP.

  • High-level signed integer arithmetic functions (mpz). There are about 130 arithmetic and logic functions in this class.

  • High-level rational arithmetic functions (mpq). This class consists of just about 25 functions, but all signed integer arithmetic functions can be used too, by applying them to the numerator and denominator separately.

  • High-level floating-point arithmetic functions (mpf). This is the GMP function class to use if the C type `double' doesn't give enough precision for an application. There are about 50 functions in this class.

  • Low-level positive-integer, hard-to-use, very low overhead functions are found in the mpn class. No memory management is performed; the caller must ensure enough space is available for the results. The set of functions is not regular, nor is the calling interface. These functions accept input arguments in the form of pairs consisting of a pointer to the least significant word, and an integral size telling how many limbs (= words) there are in that argument.

    The three first classes of functions call these low-level function for almost all their calculations.

  • Berkeley MP compatible functions.

GMP documentation (online and offline)

Complete documentation for GMP is available in the GMP Manual. It is also available for download in DVI format (43KB bzip2'ed) and in PostScript format (109KB bzip2'ed). These manual files are compressed using bzip2.

The speed of GMP varies a lot on different CPUs. See the GMP speed chart for details.

Download the latest release of GMP

Here you can download the complete sources for GMP:
ftp://ftp.freesoftware.com/pub/gnu/gmp/gmp-3.1.1.tar.gz (USA, Pacific)
ftp://ftp.sunet.se/pub/gnu/gmp/gmp-3.1.1.tar.gz (Sweden)
ftp://ftp.funet.fi/pub/gnu/prep/gmp/gmp-3.1.1.tar.gz (Finland)
ftp://ftp2.lazyfellow.com/lazyfell/pub/gnu/gmp-3.1.1.tar.gz (France)
ftp://ftp.informatik.rwth-aachen.de/pub/gnu/gmp/gmp-3.1.1.tar.gz (Germany)
ftp://ftp.unicamp.br/pub/gnu/gmp/gmp/gmp-3.1.1.tar.gz (South America)
ftp://ftp.nectec.or.th/pub/mirrors/gnu/gmp/gmp/gmp-3.1.1.tar.gz (Asia)
ftp://ftp.gnu.org/gnu/gmp/gmp-3.1.1.tar.gz (USA, East)
ftp://mirror.aarnet.edu.au/pub/gnu/gmp/gmp-3.1.1.tar.gz (Australia)

MD5 (gmp-3.1.1.tar.gz) = 7c25f129df145fd6f72455926e911791

Improving GMP

Since GMP is free software, anybody can improve it and pass on the result, as permitted by the GNU Lesser General Public License. If you need an enhancement, but don't want to do the work yourself, you can pay somebody to do it for you. Try asking bug-gmp@gnu.org! For example, clever computer manufacturers should have somebody tune GMP's speed for their machines!

If you have written an improvement, please send it to bug-gmp@gnu.org so that it may be included in the next public release. If you plan on making an improvement, please first write to the same address, to make sure your effort is not duplicated.

There are up-to-date lists of improvements we think would be useful to many users. There are both smaller tasks and larger projects.

Archives of bug-gmp are available at GNU http://mail.gnu.org/pipermail/bug-gmp or in a searchable form at Geocrawler http://www.geocrawler.com/lists/3/GNU/367/0/.

Discussing GMP

There is a mailing list for discussing GMP issues with other users and developers. Send an email to gmp-request@swox.com with the word "subscribe" in the body of the message.

Frequently asked questions

Q: Is there a C++ wrapper for GMP?

A: No, none as far as we know. Many people have started writing one, but nobody has ever sent us any useful code. "Useful" here means complete, efficient, and well-tested. (We intend to write a spec later and put it here.)

Q: When will the next release happen?

A: Not sure, but perhaps in the fall/winter 2000. It will be version 3.2.

Q: I get a Segfault/Bus error in a program that uses GMP to calculate numbers with several hundred thousand digits. Why?

A: GMP allocates most temporaries on the stack, and some machines give user programs very little stack space by default. See setrlimit(2) for information on how to increase the stack allocation. You can also change it from the shell (using ulimit or limit depending on the shell). You can also configure with --disable-alloca to instead allocate temporaries using malloc.

Q: Are there known bugs in GMP?

A: See under "Status ..." below.

Status of the current release

The current release is 3.1.1, released 2000-08-03.

Patches to GMP 3.1.1

  • There are not yet any patches for GMP 3.1.1.

Patches to GMP 3.1

Patches to GMP 3.0.1

  • This patch fixes a division bug that can cause an internal assertion failure when dividing numbers of at least a few hundred digits: gmp-3.0.1.p1.diff
  • This patch fixes a serious bug to mpz_powm that can cause it to return results equal to the mod argument, when the result should really be 0: gmp-3.0.1.p2.diff
  • There are bugs in the new random number routines that can cause the randomness to be poor, or even crashes or memory corruption. Please upgrade to GMP 3.1.1 if you need to use GMP's new random number functions.
  • configure may not automatically detect the correct CPU under cygwin and may guess i686 which is not a valid CPU. The suggested workaround is "./configure --host=pentiumpro-pc-cygwin32" (with whatever CPU is approriate in place of pentiumpro).
  • OpenBSD 2.6 m4 has a bug in eval, making it unsuitable for asm file processing. Upgrade to OpenBSD 2.7 (or later), or use GNU m4.

Patches to GMP 3.0

  • This patch converts GMP 3.0 to GMP 3.0.1: gmp-3.0-3.0.1.diff.gz
  • All patches for GMP 3.0.1 also apply to GMP 3.0. Please first upgrade to GMP 3.0.1 and then apply any patches to that release from the list above.

For patches to GMP 2, please see the GMP 2 status page.

Projects using GMP

There are several interesting projects that rely on GMP. Here are some of the ones we are aware of:
  • lsh is a project to develop a free (GPLed) implementation of the Secure Shell protocol V2; it is discussed on the psst.. mailing list.
  • LiDIA, an object-oriental library which provides datatypes and algorithms for doing computational number theory. The system has a replaceable arithmetic kernel, which can use many different integer packages (at the moment gmp, cln, lip, libI, piologie).
  • Paul Zimmermann implemented Lenstra's Elliptic Curve Method (ECM) for integer factorization using GMP. He runs a factorization project known as ECMNET.
  • Paul Zimmermann also implemented Uspensky's algorithm for finding real roots of polynomials with integer coefficients. The source code is available here.
  • CLN by Bruno Haible, which uses low-level routines from GMP to build a different high-level user interface.
  • My own repunit factoring and prime search project...
  • The Kaffe project . The well-known Java machine.
There are also several projects using GMP to produce non-free software. It's too bad they chose not to share their work with the rest of us, and we won't add pointers to such projects, no matter how interesting! The EU sponsors lots of projects, several of them being based on GMP. But the EU requires that the result of projects they sponsor be non-free, which caused them to quickly be forgotten. (It is a shame for Europe that almost all cool free software is written in USA! Just think of GNU, X Windows, MIT Athena, Coda, Berkely Unix (FreeBSD, NetBSD), etc, etc. We should be grateful the EU never got any money into Linux, because then you would never have heard of it and it would just run on some obscure Transputer-based computer...!)

Try GMP!

Enter an integer expression in the field below. The expression may include +, -, *, /, %, ^ (exponentiation), and ! (factorial), the n-ary functions `gcd', `lcm', `and', `ior', `xor', `mul', `plus', the binary functions `minus', `div', `mod', `rem', and the unary function `popc' (population count). Most functions may also be used in infix form. All constants must be integers.

An example of a valid expression is:

1 + gcd(87324,78263148,7896) * (10^1989879887 mod 471!)

This is computed on a 200MHz Amd K6 running FreeBSD.

If you want to know how to do things such as this with GMP, take a look at demos/pexpr.c in the GMP distribution, the program used to compute these expressions.

Future releases

We plan to make more frequent releases of GMP now that GMP 3 has been released. We hope to follow up the GMP 3.0 and GMP 3.1 releases with GMP 3.2 in the autumn/winter 2000.


Please send comments about this page to webmaster@swox.com.
Copyright (C) 2000 Free Software Foundation (subject to GPL).
Valid HTML 3.2!