Jump to content

GNU Multiple Precision Arithmetic Library

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 90.132.75.8 (talk) at 06:49, 3 November 2010 (rv edits by user aloopingicon. See (and please really read) discussion page.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
GNU Multiple-Precision Library
Developer(s)The GNU Project
Stable release
5.0.1 / February 6, 2010 (2010-02-06)
Repository
Written inC
Operating systemCross-platform
TypeMathematical software
LicenseLGPL
Websitehttp://gmplib.org/

The GNU Multiple-Precision Library, also known as 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 (operand dimension limit is 231 bits on 32-bit machines and 237 bits on 64-bit machines[1]). 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 C++, C#, OCaml, Perl, PHP, and Python. Kaffe Java virtual machine have also used GMP to support Java built-in arbitrary precision arithmetics in the past. This feature has been removed from the recent releases, causing protests from people that claim they used Kaffe for the sole reason GMP arithmetic being much faster than the typical implementations in other Java distributions[2]. As a result, GMP support has been added to GNU Classpath [3].

The main target applications for 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 towards this end are:

Here is an example of C code using the GMP library. It shows how GMP can calculate large numbers.

#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>

int main(void)
{
 mpz_t x;
 mpz_t y;
 mpz_t result;

 mpz_init(x);
 mpz_init(y);
 mpz_init(result);

 mpz_set_str(x, "7612058254738945", 10);
 mpz_set_str(y, "9263591128439081", 10);

 mpz_mul(result, x, y);
 gmp_printf("\n    %Zd\n*\n    %Zd\n--------------------\n%Zd\n\n", x, y, result);
 return EXIT_SUCCESS;
}

This code calculates the value of 7612058254738945 * 9263591128439081.

Compiling and running this program gives this result. (You need to use the -lgmp flag if compiling under Unix-type systems.)

    7612058254738945
*
    9263591128439081
--------------------
70514995317761165008628990709545

The first GMP release was made in 1991. It is continually developed and maintained. The current release is 5.0.1.

GMP is part of the GNU project (although the fact that its website is not on gnu.org might cause confusion), and is distributed under the GNU LGPL.

GMP is used for integer arithmetic in many computer algebra systems such as Mathematica[4] and Maple[5].

GMP is required for building GCC.[6]

Language Bindings

Library Name Language License
GNU Multi-Precision Library C / C++ LGPL
Math::GMP Perl
GNU Multi-Precision Library for .NET C# / .NET LGPL
General Multiprecision Python Project Python
The RubyGems project Ruby
GNU Multi-Precision Library for PHP PHP PHP License

See also

  • MPFR - library for arbitrary-precision computations with correct rounding, based on GNU MP

References