GNU Multiple Precision Arithmetic Library | |
Developer: | GNU Project |
Released: | [1] |
Programming Language: | C, (C++, assembly optionally) |
Genre: | Mathematical software |
License: | Dual LGPLv3 and GPLv2 |
GNU Multiple Precision Arithmetic Library (GMP) is a free library for arbitrary-precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers.[2] There are no practical limits to the precision except the ones implied by the available memory (operands may be of up to 232−1 bits on 32-bit machines and 237 bits on 64-bit machines).[3] [4] GMP has a rich set of functions, and the functions have a regular interface. The basic interface is for C, but wrappers exist for other languages, including Ada, C++, C#, Julia, .NET, OCaml, Perl, PHP, Python, R, Ruby, and Rust. Prior to 2008, Kaffe, a Java virtual machine, used GMP to support Java built-in arbitrary precision arithmetic.[5] Shortly after, GMP support was added to GNU Classpath.[6]
The main target applications of GMP are cryptography applications and research, Internet security applications, and computer algebra systems.
GMP aims to be faster than any other bignum library for all operand sizes. Some important factors in doing this are:
The first GMP release was made in 1991. It is constantly developed and maintained.[7]
GMP is part of the GNU project (although its website being off gnu.org may cause confusion), and is distributed under the GNU Lesser General Public License (LGPL).
GMP is used for integer arithmetic in many computer algebra systems such as Mathematica[8] and Maple.[9] It is also used in the Computational Geometry Algorithms Library (CGAL).
GMP is needed to build the GNU Compiler Collection (GCC).[10]
Here is an example of C code showing the use of the GMP library to multiply and print large numbers:
int main(void)
This code calculates the value of 7612058254738945 × 9263591128439081.
Compiling and running this program gives this result. (The -lgmp
flag is used if compiling on Unix-type systems.)
9263591128439081--------------------70514995317761165008628990709545
For comparison, one can write instead the following equivalent C++ program. (The -lgmpxx -lgmp
flags are used if compiling on Unix-type systems.)
int main