GMP - Arithmetic without limitations Welcome to the GMP web pages! Here you can find information about the GNU Multiple Precision Arithmetic Library, the fastest bignum library on the planet!

GMPbench results (with preliminary 4.3 numbers!)
Is 64-bit slower?
Compute billions of digits of Pi using GMP!
GMP development tidbits
GMP current nightly testing hosts
Enterprises supporting GMP?
Support the fight against
software patents!
Join the FFII!
The GMP site is
Powered by Wind!
Page contents:
What is GMP?
Function categories
Improving GMP
Reporting bugs
Mailing lists
Current release status
Projects using GMP
Try GMP!
Future releases


GMP is very often miscompiled! Please never use your newly compiled libgmp.a or without first running make check. If it doesn't complete without errors, don't trust the library. Please try another compiler release, or change optimization flags until it works. If you don't have the skill to isolate the problem, please report it to us if it was a GMP bug; else to the compiler vendor. (The compilers that cause most problems are HP's unbundled compilers and GCC, in particular Apple's GCC 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 practical 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.

The main target applications for GMP are cryptography applications and research, Internet security applications, algebra systems, computational algebra research, etc.

GMP is carefully 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 highly optimized assembly code for the most common inner loops for a lot of CPUs, and by a general emphasis on speed.

GMP is faster than any other bignum library. The advantage for GMP increases with the operand sizes for many operations, since GMP uses asymptotically faster algorithms.

The first GMP release was made in 1991. It is continually developed and maintained, with a new release about once a year.

GMP is distributed under the GNU LGPL. This license makes the library free to use, share, and improve, and allows you to pass on the result. The license gives freedoms, but also sets firm restrictions on the use with non-free programs.

GMP is part of the GNU project. For more information about the GNU project, please see the official GNU web site.

GMP is brought to you by a team listed in the manual.

GMP function categories

There are several categories of functions in GMP:

  1. High-level signed integer arithmetic functions (mpz). There are about 140 arithmetic and logic functions in this category.
  2. High-level rational arithmetic functions (mpq). This category consists of about 35 functions, but all signed integer arithmetic functions can be used too, by applying them to the numerator and denominator separately.
  3. High-level floating-point arithmetic functions (mpf). This is the GMP function category to use if the C type `double' doesn't give enough precision for an application. There are about 65 functions in this category.
  4. C++ class based interface to all of the above. (The C functions and types can of course be used directly from C++ too.)
  5. Low-level positive-integer, hard-to-use, very low overhead functions are found in the mpn category. 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 functions in the other categories call mpn for almost all their calculations.
  6. Berkeley MP compatible functions.
  7. Externally supported: High-level floating-point accurately rounding arithmetic functions (mpfr). See the mpfr site for more information. Starting with GMP 4.2, mpfr is released only separately from the project site.

GMP documentation (online and offline)

Complete documentation for GMP is available in the online GMP Manual. It is also available for download in a number of formats:
DVI format 170078 bytes bzip2'ed
PostScript format 320601 bytes bzip2'ed
PDF format 1002466 bytes
These manual files are compressed using bzip2.

The speed of GMP varies a lot on different CPUs. See the GMPbench 0.1 results, or the really obsolete GMP speed chart for details.

Download the latest release of GMP

Sweden, gmp-4.2.4.tar.bz2 gmp-4.2.4.tar.gz
USA, East, gmp-4.2.4.tar.bz2 gmp-4.2.4.tar.gz

To try to verify that the file you have downloaded has not been tampered with, you can check that the GnuPG signature matches the contents of the file. Use your GnuPG software or a key server directly to get the key that was used for creating the signature. These are the properties of the signing key:

Name: Swox AB (Software signing key 2004) <>
Key ID: 0xDB899F46
Key type: 1024 bit DSA
Fingerprint: 73D4 6C36 6746 1E4B D939 7249 5D6D 47DF DB89 9F46

The GnuPG signature of gmp-4.2.4.tar.bz2 is here:

The GnuPG signature of gmp-4.2.4.tar.gz is here:

Alternatively, you could check the MD5 checksum:

MD5 (gmp-4.2.4.tar.bz2) = fc1e3b3a2a5038d4d74138d0b9cf8dbe
MD5 (gmp-4.2.4.tar.gz) = 430f966bf8fe28d45ad8670a52b40e8c
SHA1 (gmp-4.2.4.tar.bz2) = bb721f94fbeeb8c609104540b408da6707c370ec
SHA1 (gmp-4.2.4.tar.gz) = a92b7a67543010ed917c054c01de67732b8d91a9

Improving GMP

Since GMP is free software, anybody can improve it and pass on the result, as permitted by the GNU LGPL. 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! For example, clever computer manufacturers should have somebody tune GMP for their processors!

If you have written an improvement, please send it to so that it may be included in the next public release. If you are working on an improvement, please 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. Some of these projects have a section at the GMP development tidbits page.

Reporting bugs in GMP

Please first see the manual on how to report bugs. The FAQ below might also be useful reading. The proper address for bug reports is

Most problems with compiling GMP these days are due to problems not in GMP, but with the compiler. In the past, system compilers caused the most trouble, but in the last years, gcc has gradually caused more and more trouble. Here, we don't list compiler problems, just problems with the GMP code itself. To save you some time, we suggest that you cut any compiler error message and paste them into your favourite web search engine before you report problems to the GMP bug report list.

GMP mailing lists

List Subscribe URL Archive URL

The list is intended for bug reports. Please do not send general questions to that list. Information on how to write useful bug reports is available in the manual. Archives of the now obsolete bug report mailing list are available at the main GNU site

The list is where important announcements from the GMP maintainers are made. All GMP users should be on this list. It is really very low volume (around one message per year).

The list is intended for discussing GMP issues with other users and developers. This is NOT for bug reports. This is the right place to ask questions, but please check the manual first.

The list is for the technical discussions between GMP developers, and in general, non-developers will not be allowed to post here. Therefore, this list is moderated.

Note that we perform spam and virus filtering of these lists. The lists have been 100% spam-free during the last years.

Frequently asked questions

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

A1: Yes, beginning with GMP 4.0 one is bundled with the release.

Q2: When will the next release happen?

A2: See Future releases below.

Q3: I get a segfault in a program that uses GMP to calculate numbers with several hundred thousand digits. Why?

A3: Upgrade to GMP 4.2.x. (Previous version of GMP allocated huge blocks of temporary memory on the stack, causing problems for some system.)

Q4: Are there known bugs in GMP?

A4: See under "Status ..." right below.

Q5: When running make check or when trying to link my program to gmp, I get error messages about What's the deal?

A5: As the name suggests, is a gcc support library. It is not within GMP's power to locate this file. You need to find out why your gcc installation doesn't properly point to its internal files.

Status of the current release

The current release is 4.2.4, released 2008-09-19. It fixes some minor problems found in 4.2.3. Note that we did not to work around all compiler bugs in this release. Never forget to do  make check  after building the library to make likely it was not miscompiled!

Issues with GMP 4.2.4:

Additional issues with GMP 4.2.3:

Additional issues with GMP 4.2.2:

Additional issues with GMP 4.2.1:

Additional issues with GMP 4.2:

For patches to older GMP versions, please see the Info on older GMP releases.

Projects using GMP

There are many interesting projects that rely on GMP. Here are a few examples:

Try GMP!

Demo 1 -- Integer expressions

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 1460MHz AMD Athlon XP running FreeBSD.

This is computed by demos/pexpr.c from the GMP distribution.

Demo 2 -- Find Anagrams

Max number of words in generated anagrams: 1    2   3 (many matches!)
Language: English   Swedish

The program generating these anagrams forms special sums representing the characters of a string, adds and compares such sums to figure out what strings can be combined. Since the sums can be several hundred bits large, GMP comes in handy.

Future releases

GMP 4.3.0 will be released late 2008 or early 2009. It will come with speed improvements to various functions, as well as better assembly code for several machines. Parts of the new mpn layer planned for GMP 5 will be available in GMP 4.3, but it will have a preliminary, undocumented interface.

GMP 5 is planned to come out in a couple of years. This release will make all functions of GMP sub-quadratic, including gcd, gcdext, exact division, modular computation (by means of redc), etc. Truncating division will be improved from O(M(n)log(n)) to O(M(n)). The mpn layer will be extended to be much more complete, and mpz will as a result become simpler. More complete list:

Please send comments about this page to
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.