World Library  
Flag as Inappropriate
Email this Article

GNU Multiple Precision Arithmetic Library

Article Id: WHEBN0000483126
Reproduction Date:

Title: GNU Multiple Precision Arithmetic Library  
Author: World Heritage Encyclopedia
Language: English
Subject: MPIR (mathematics software), Rational data type, GNU, Federico Heinz, Henry Poole (technologist)
Publisher: World Heritage Encyclopedia

GNU Multiple Precision Arithmetic Library

GNU Multiple Precision Arithmetic Library
Developer(s) GNU Project
Initial release 1991 (1991)[1]
Stable release 6.0.0 (24 March 2014 (2014-03-24) [2])
Written in C, (C++, assembly optionally)
Operating system Cross-platform
Type Mathematical software
License Dual LGPLv3 and GPLv2[3]
Website .orggmplib

The GNU Multiple Precision Arithmetic Library (GMP) is a free library for arbitrary-precision arithmetic, operating on signed integers, rational numbers, and floating point numbers.[3] There are no practical limits to the precision except the ones implied by the available memory in the machine GMP runs on (operand dimension limit is 232-1 bits on 32-bit machines and 237 bits on 64-bit machines).[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#, OCaml, Perl, PHP, and Python. In the past, the Kaffe Java virtual machine used GMP to support Java built-in arbitrary precision arithmetic. This feature has been removed from recent releases, causing protests from people who claim that they used Kaffe solely for the speed benefits afforded by GMP.[5] As a result, GMP support has been 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.[1]

GMP is part of the GNU Lesser General Public License (LGPL).

GMP is used for integer arithmetic in many computer algebra systems such as Mathematica[7] and Maple.[8] It is also used in the Computational Geometry Algorithms Library (CGAL) because geometry algorithms tend to 'explode' when using ordinary floating point CPU math.[9]

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)
 mpz_t x;
 mpz_t y;
 mpz_t result;


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

 mpz_mul(result, x, y);
            "    %Zd\n"
            "    %Zd\n"
            "\n", x, y, result);

 /* free used memory */

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


For simplicity, one can write instead the following equivalent C++ program. (The -lgmpxx -lgmp flags are used if compiling on Unix-type systems.)


int main()
  mpz_class x("7612058254738945");
  mpz_class y("9263591128439081");

  std::cout << "\n    " << x << "\n*\n    " << y;
  std::cout << "\n--------------------\n" << x * y << "\n\n";
  return 0;

Language bindings

Library name Language License
GNU Multi-Precision Library C, C++ LGPL
Math::GMP Perl GPL
GNU Multi-Precision Library for .NET C#, .NET LGPL
General Multiprecision Python Project Python LGPL
The RubyGems project Ruby Apache 2.0
GNU Multi-Precision Library for PHP PHP PHP
GNU Multi-Precision Routines for SBCL Common Lisp Public Domain
Ch GMP Ch Proprietary
Glasgow Haskell Compiler
(The implementation of Integer
is basically a binding to GMP)
Haskell BSD

See also

  • MPFR – library for arbitrary-precision computations with correct rounding, based on GNU MP
  • CLN – a class library for arbitrary precision
  • MPIR – a fork of GMP with mostly compatible interface which aims to provide MSVC-based compilation system for Windows platforms


  1. ^ a b "The GNU MP Bignum Library". Retrieved 2013-03-17. 
  2. ^ V6.0.0
    "The GNU MP Bignum Library". Retrieved 2014-04-21. 
  3. ^ a b "What is GMP?". Retrieved 2014-04-07. 
  4. ^ Granlund, Torbjorn (2009-07-06). "Problems with mpz_set_str and huge strings". Retrieved 2013-03-17. 
  5. ^ Hughes, Andrew John (2008-02-28). "Removed GMP math?". Retrieved 2013-03-17. 
  6. ^ """GNU Classpath 0.98 "Better Late Than Never. 2009-02-05. Retrieved 2013-03-17. 
  7. ^ "The Mathematica Kernel: Issues in the Design and Implementation". October 2006. Retrieved 2013-03-17. 
  8. ^ "The GNU Multiple Precision (GMP) Library".  
  9. ^ "CGAL Manuals". 
  10. ^ GCC uses the  

External links

  • Official website
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.