Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
GNU Multiple Precision Arithmetic Library
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Free software}} {{Infobox software | name = GNU Multiple Precision Arithmetic Library | logo = GMPLogo.svg | screenshot = | caption = | developer = [[GNU Project]] | released = {{Start date and age|1991}}<ref>{{cite web | url=https://gmplib.org/download/gmp/archive/ | title=GNU MP archive | access-date=2018-12-03}}</ref> | latest release version = {{wikidata|property|preferred|references|edit|Q1205818|P348|P548=Q2804309}} | latest release date = {{wikidata|qualifier|preferred|single|Q1205818|P348|P548=Q2804309|P577}} | latest preview version = {{wikidata|property|preferred|references|edit|Q1205818|P348|P548=Q51930650}} | latest preview date = {{wikidata|qualifier|preferred|single|Q1205818|P348|P548=Q51930650|P577}} | programming language = [[C (programming language)|C]], ([[C++]], [[assembly language|assembly]] optionally) | genre = [[Mathematical software]] | license = Dual [[GNU Lesser General Public License|LGPLv3]] and [[GNU General Public License|GPLv2]]<ref name=what/> | website = {{URL|https://gmplib.org}} | repo = {{URL|https://gmplib.org/repo/}} }} '''GNU Multiple Precision Arithmetic Library''' ('''GMP''') is a [[free software|free]] library for [[arbitrary-precision arithmetic]], operating on [[Sign (mathematics)|signed]] [[integer]]s, [[Rational data type|rational numbers]], and [[Floating-point arithmetic|floating-point numbers]].<ref name=what>{{cite web | url=https://gmplib.org/#WHAT | title=What is GMP? | access-date=2014-04-07}}</ref> There are no practical limits to the precision except the ones implied by the available [[virtual memory|memory]] (operands may be of up to 2<sup>32</sup>β1 bits on 32-bit machines and 2<sup>37</sup> bits on 64-bit machines).<ref>{{cite web | url=https://gmplib.org/list-archives/gmp-bugs/2009-July/001538.html | title=Problems with mpz_set_str and huge strings | last=Granlund | first=Torbjorn | date=2009-07-06 | access-date=2013-03-17}}</ref><ref>{{cite web | url=https://gmplib.org/gmp6.0.html | title=GMP 6.0 News | access-date=2019-10-04}}</ref> GMP has a rich set of functions, and the functions have a regular interface. The basic interface is for [[C (programming language)|C]], but [[Wrapper function|wrappers]] exist for other languages, including [[Ada (programming language)|Ada]], [[C++]], [[C Sharp (programming language)|C#]], [[Julia (programming language)|Julia]], [[.NET Framework|.NET]], [[OCaml]], [[Perl]], [[PHP]], [[Python (programming language)|Python]], [[R (programming language)|R]], [[Ruby (programming language)|Ruby]], and [[Rust (programming language)|Rust]]. Prior to 2008, [[Kaffe]], a [[Java virtual machine]], used GMP to support Java built-in arbitrary precision arithmetic.<ref>{{cite web | url=http://www.kaffe.org/pipermail/kaffe/2008-February/191039.html | title=Removed GMP math? | last=Hughes | first=Andrew John | date=2008-02-28 | access-date=2013-03-17}}</ref> Shortly after, GMP support was added to [[GNU Classpath]].<ref>{{cite web | url=https://www.gnu.org/software/classpath/announce/20090205.html | title=GNU Classpath 0.98 "Better Late Than Never" | date=2009-02-05 | access-date=2013-03-17}}</ref> The main target applications of GMP are [[cryptography]] applications and research, Internet security applications, and [[computer algebra system]]s. GMP aims to be faster than any other [[bignum]] library for all operand sizes. Some important factors in doing this are: * Full [[word (data type)|words]] are the basic type for all arithmetic. * Different [[algorithm]]s are used for different [[operand]] sizes; algorithms which are more efficient with large numbers are not used when dealing with small numbers. * [[Assembly language]] (specialized for different [[central processing unit|processors]]) is used in the most common inner loops to [[optimization_(computer_science)|optimize]] them as much as possible. The first GMP release was made in 1991. It is constantly developed and maintained.<ref name=main>{{cite web | url=https://gmplib.org/ | title=GNU MP Bignum Library | access-date=2018-12-03}}</ref> 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 system]]s such as [[Mathematica]]<ref>{{cite web | url=https://library.wolfram.com/infocenter/Conferences/7518/Macalester_talk.txt | title=The Mathematica Kernel: Issues in the Design and Implementation | date=October 2006 | access-date=2013-03-17}}</ref> and [[Maple (software)|Maple]].<ref>{{cite web | url=https://www.maplesoft.com/support/help/AddOns/view.aspx?path=GMP | title= The GNU Multiple Precision (GMP) Library | publisher=[[Maplesoft]] | access-date=2013-03-17}}</ref> It is also used in the [[Computational Geometry Algorithms Library]] (CGAL). GMP is needed to build the [[GNU Compiler Collection]] (GCC).<ref>GCC uses the [[GNU MPFR]] library, which in turn relies on GMP. {{cite web | url=https://gcc.gnu.org/gcc-4.3/changes.html#mpfropts | title=GCC 4.3 Release Series: Changes, New Features, and Fixes | date=2012-11-02 | access-date=2013-03-17}}</ref> == Examples == Here is an example of C code showing the use of the GMP library to multiply and print large numbers: <syntaxhighlight lang="C"> #include <stdio.h> #include <gmp.h> int main(void) { mpz_t x, y, result; mpz_init_set_str(x, "7612058254738945", 10); mpz_init_set_str(y, "9263591128439081", 10); mpz_init(result); mpz_mul(result, x, y); gmp_printf(" %Zd\n" "*\n" " %Zd\n" "--------------------\n" "%Zd\n", x, y, result); /* free used memory */ mpz_clear(x); mpz_clear(y); mpz_clear(result); return 0; } </syntaxhighlight> This code calculates the value of 7612058254738945 Γ 9263591128439081. Compiling and running this program gives this result. (The <code>-lgmp</code> flag is used if compiling on Unix-type systems.) <syntaxhighlight lang="text"> 7612058254738945 * 9263591128439081 -------------------- 70514995317761165008628990709545 </syntaxhighlight> For comparison, one can write instead the following equivalent C++ program. (The <code>-lgmpxx -lgmp</code> flags are used if compiling on Unix-type systems.) <syntaxhighlight lang="cpp"> #include <iostream> #include <gmpxx.h> int main() { mpz_class x("7612058254738945"); mpz_class y("9263591128439081"); std::cout << " " << x << "\n" << "*\n" << " " << y << "\n" << "--------------------\n" << x * y << "\n"; return 0; } </syntaxhighlight> == Language bindings == {| class="wikitable" |- ! Library name ! Language ! License |- | [https://gmplib.org/ GNU Multi-Precision Library] | [[C (programming language)|C]], [[C++]] | [[GNU Lesser General Public License|LGPL]] |- | [https://metacpan.org/pod/Math::GMP Math::GMP] | [[Perl]] | [[GNU Lesser General Public License|LGPL]] |- | [https://metacpan.org/pod/Math::GMPz Math::GMPz], [https://metacpan.org/pod/Math::GMPf Math::GMPf] and [https://metacpan.org/pod/Math::GMPq Math::GMPq] | [[Perl]] | [[Artistic License]] v1.0 + [[GNU General Public License|GPL]] v1.0-or-later |- | [https://github.com/aleaxit/gmpy General Multiprecision Python Project] | [[Python (programming language)|Python]] | LGPL |- | [https://cran.r-project.org/web/packages/gmp/index.html R package 'gmp'] | [[R (programming language)|R]] | GPL |- | [https://rubygems.org/gems/gmp The RubyGems project] | [[Ruby (programming language)|Ruby]] | [[Apache License|Apache 2.0]] |- | [https://lib.rs/crates/gmp-mpfr-sys Rust FFI bindings for GMP, MPFR and MPC] | [[Rust (programming language)|Rust]] | [[GNU Lesser General Public License|LGPL]] |- | [https://www.php.net/gmp GNU Multi-Precision Library for PHP] | [[PHP]] | [[PHP License|PHP]] |- | [http://www.math.uni.wroc.pl/~hebisch/prog/ GNU Multi-Precision Routines for SBCL] | [[Common Lisp]] | [[Public domain software|Public Domain]] |- | [http://chgmp.sourceforge.net/ Ch GMP] | [[Ch (computer programming)|Ch]] | [[Proprietary software|Proprietary]] |- | [http://bmdfm.com/ Parallel GMP Wrapper for BMDFM] | [[BMDFM | BMDFM LISP / C]] | [[Public domain software|Public Domain]] |- | [[Glasgow Haskell Compiler]]<br /><small>(The implementation of <code>Integer</code><br />is basically a binding to GMP)</small> | [[Haskell (programming language)|Haskell]] | [[BSD licenses|BSD]] |- | [https://github.com/Playermet/luajit-gmp luajit-gmp] | [[Lua (programming language)|LuaJIT]] | [[MIT License|MIT]] |- | [https://code.google.com/archive/p/gmp-wrapper-for-delphi gmp-wrapper-for-delphi] | [[Delphi (programming language)|Delphi]] | [[MIT License|MIT]] |- | [https://github.com/ocaml/Zarith Zarith] | [[OCaml]] | LGPL |- | [https://github.com/MachineCognitis/Math.Gmp.Native Math.Gmp.Native Library] | [[.NET Framework|.NET]] | [[MIT License|MIT]] |- | [https://github.com/FedeOmoto/nim-gmp nim-gmp] | [[Nim (programming language)|Nim]] | [[MIT License|MIT]] |- | [https://github.com/jandom-devel/JGMP JGMP] | [[Java (programming language)|Java]] | [[GNU Lesser General Public License|LGPL]] |} == See also == * [[GNU MPFR]] β a library for arbitrary-precision computations with correct rounding, based on GNU MP * [[Class Library for Numbers|CLN]] β a class library for arbitrary precision * [[MPIR (mathematics software)|MPIR]] β a fork of GMP, not maintained any more == References == {{Reflist}} == External links == * {{Official website}} {{GNU}} {{Authority control}} {{DEFAULTSORT:Gnu Multi-Precision Library}} [[Category:Assembly language software]] [[Category:C (programming language) libraries]] [[Category:Computer arithmetic]] [[Category:Free software programmed in C]] [[Category:GNU Project software|Multiple Precision Arithmetic Library]] [[Category:Numerical libraries]] [[Category:Software using the GNU Lesser General Public License]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Authority control
(
edit
)
Template:Cite web
(
edit
)
Template:GNU
(
edit
)
Template:Infobox software
(
edit
)
Template:Official website
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)