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!



♦Documentation: Online | PDF
♦Download: gmp-4.3.1.tar.bz2 | Release notes
♦Development: GMP repository - Repo usage tips | Daily snapshots
♦Testing: Current status
♦GMPbench: Results | Download benchmark sources
♦Fun: Compute billions of digits of Pi using GMP!
♦Sponsor us: Enterprises supporting GMP?
Support the fight against
software patents!
Join the FFII!
Page contents:
What is GMP?
Function categories
Download
Improving GMP
Reporting bugs
Mailing lists
FAQ
Current release status
Projects using GMP
Try GMP!
Future releases
    

IMPORTANT INFORMATION FOR ALL GMP USERS:

GMP is very often miscompiled! Please never use your newly compiled libgmp.a or libgmp.so without first running make check. If it doesn't complete without errors, don't trust the library. Please try another compiler release, or change optimisation flags until it works. If you don't have the skill to isolate the problem, please report it to us as 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.)

N.B. gcc 4.3.2 miscompiles GMP 4.3.x on 64-bit machines. The problem is specific to that very release; specifically gcc 4.3.1 and 4.3.3 seem to work fine.

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 optimised 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's main target platforms are Unix-type systems, such as GNU/Linux, Solaris, HP-UX, Mac OS X/Darwin, BSD, AIX, etc. It also is known to work on Windoze in 32-bit mode.

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

GMP is carefully developed and maintained, both technically and legally. We of course inspect and test contributed code carefully, but equally importantly we make sure we have the legal right to distribute the contributions, meaning users can safely use GMP. To achieve this, we will ask contributors to sign paperwork where they allow us to distribute their work.

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 separately from GMP. (New projects should probably use mpfr instead of mpf.)

Download the latest release of GMP

Location lz, 1559818 bytes bz2, 1881090 bytes gz, 2492100 bytes
Sweden, gmplib.org gmp-4.3.1.tar.lz gmp-4.3.1.tar.bz2 gmp-4.3.1.tar.gz
USA, ftp.gnu.org   gmp-4.3.1.tar.bz2 gmp-4.3.1.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) <info@swox.com>
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.3.1.tar.bz2 is here: gmp-4.3.1.tar.bz2.sig

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

Alternatively, you could check a cryptographic checksum:
SHA1 gmp-4.3.1.tar.bz2 acbd1edc61230b1457e9742136994110e4f381b2
SHA1 gmp-4.3.1.tar.gz 0792e63f3aa6eed0cd6eaa20043172b5c7e4d8fe
SHA256 gmp-4.3.1.tar.bz2 aa0295472854f2f9691db7c6892921452521b4d5def15223136f4733309db7c8
SHA256 gmp-4.3.1.tar.gz 7ffa2ee7c85f998844c107db2ecce55ab4b7398f49a2fc0d7308e3e6c74fd1e6

You may also get the latest code from the open GMP repository.

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 gmp-devel@gmplib.org! For example, clever computer manufacturers should have somebody tune GMP for their processors!

If you have written an improvement, please send it to gmp-devel@gmplib.org 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.

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 gmp-bugs@gmplib.org.

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. On these pages 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 it into your favourite web search engine before you report problems to the GMP bug report list.

GMP mailing lists

List Subscribe URL Archive URL
gmp-bugs@gmplib.org http://gmplib.org/mailman/listinfo/gmp-bugs http://gmplib.org/list-archives/gmp-bugs/
gmp-announce@gmplib.org http://gmplib.org/mailman/listinfo/gmp-announce http://gmplib.org/list-archives/gmp-announce/
gmp-discuss@gmplib.org http://gmplib.org/mailman/listinfo/gmp-discuss http://gmplib.org/list-archives/gmp-discuss/
gmp-devel@gmplib.org http://gmplib.org/mailman/listinfo/gmp-devel http://gmplib.org/list-archives/gmp-devel/

The gmp-bugs@gmplib.org 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. The now obsolete bug report mailing list bug-gmp@gnu.org is archived at the main GNU site.

The gmp-announce@gmplib.org 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 5 messages per year).

The gmp-discuss@gmplib.org 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 gmp-devel@gmplib.org 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.

You cannot subscribe an AOL address to any GMP mailing list, since AOL blocks our mail server until we register with them as a "bulk mailer", something we will certainly never do.

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 or later. (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 libgcc_s.so.1. What's the deal?

A5: As the name suggests, libgcc_s.so.1 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.3.1, released 2009-05-12.

Issues with GMP 4.3.1:

Additional issues with GMP 4.3.0:

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, in alphabetic order:

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 2667MHz Intel Core i7 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

We might make some further minor bug/portability fix releases, 4.3.x during 2009.

GMP 4.4 is planned for the 2nd half of 2009. Here are some examples of the planned improvements:

The GMP project was run semi-commercially until January 2008, but has since then returned to academia with proper funding. This means that we will be able to make releases more frequently. It also means that old release plans have changed. We've been talking about GMP 5 for many years, outlining specific goals for that release. These plans are now more-or-less scrapped, and we will instead gradually implement the features previously planned for GMP 5 in 4.x.

The following description of GMP 5 is therefore outdated:

GMP 5 will be released as soon as it is ready. This release will make all major functions of GMP asymptotically optimal. 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 gmp-discuss@gmplib.org
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.