GNU Multiple Precision Arithmetic Library explained

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]

Examples

Here is an example of C code showing the use of the GMP library to multiply and print large numbers:

  1. include
  2. include

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.)

7612058254738945

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.)

  1. include
  2. include

int main

Language bindings

Library nameLanguageLicense
GNU Multi-Precision LibraryC, C++LGPL
Math::GMPPerlLGPL
Math::GMPz, Math::GMPf and Math::GMPqPerlArtistic License v1.0 + GPL v1.0-or-later
General Multiprecision Python ProjectPythonLGPL
R package 'gmp'RGPL
The RubyGems projectRubyApache 2.0
Rust FFI bindings for GMP, MPFR and MPCRustLGPL
GNU Multi-Precision Library for PHPPHPPHP
GNU Multi-Precision Routines for SBCLCommon LispPublic Domain
Ch GMPChProprietary
Parallel GMP Wrapper for BMDFMBMDFM LISP / CPublic Domain
Glasgow Haskell Compiler
(The implementation of Integer
is basically a binding to GMP)
HaskellBSD
luajit-gmpLuaJITMIT
gmp-wrapper-for-delphiDelphiMIT
ZarithOCamlLGPL
Math.Gmp.Native Library.NETMIT
nim-gmpNimMIT
JGMPJavaLGPL

See also

Notes and References

  1. Web site: GNU MP archive . 2018-12-03.
  2. Web site: What is GMP?. 2014-04-07.
  3. Web site: Problems with mpz_set_str and huge strings. Granlund. Torbjorn. 2009-07-06. 2013-03-17.
  4. Web site: GMP 6.0 News. 2019-10-04.
  5. Web site: Removed GMP math?. Hughes. Andrew John. 2008-02-28. 2013-03-17.
  6. Web site: GNU Classpath 0.98 "Better Late Than Never". 2009-02-05. 2013-03-17.
  7. Web site: GNU MP Bignum Library . 2018-12-03.
  8. Web site: The Mathematica Kernel: Issues in the Design and Implementation. October 2006. 2013-03-17.
  9. Web site: The GNU Multiple Precision (GMP) Library. Maplesoft. 2013-03-17.
  10. GCC uses the GNU MPFR library, which in turn relies on GMP. Web site: GCC 4.3 Release Series: Changes, New Features, and Fixes. 2012-11-02. 2013-03-17.