GNU Multiple Precision Arithmetic Library
| Developer(s) | GNU Project |
|---|---|
| Initial release | 1991[1] |
| Stable release | 5.0.4 (February 10, 2012[2]) [±] |
| Written in | C |
| Operating system | Cross-platform |
| Type | Mathematical software |
| License | LGPL |
| Website | http://gmplib.org/ |
The GNU Multiple Precision Arithmetic Library, also known as GMP, is a free library for arbitrary-precision arithmetic, operating on signed integers, rational numbers, and floating point numbers. 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 231 bits on 32-bit machines and 237 bits on 64-bit machines[3][not in citation given (See discussion.)]). 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. 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.[4] As a result, GMP support has been added to GNU Classpath.[5]
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 towards this end are:
- Using full words as the basic arithmetic type.
- Using different algorithms for different operand sizes. The algorithms that are fastest for really big numbers are seldom fastest for small numbers.
- Highly optimized assembly code for the most important inner loops, specialized for different processors.
The first GMP release was made in 1991. It is continually developed and maintained.[1] The current release is 5.0.2.
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[6] and Maple.[7]
GMP is required for building GCC.[8]
Contents |
[edit] Example
Here is an example of C code showing the use of the GMP library to multiply and print 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); /* free used memory */ mpz_clears(x, y, result, NULL); 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
[edit] Criticism
GMP has been criticized for its perceived lackluster support of Microsoft Windows and Microsoft Visual Studio.[9][10]
[edit] 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 |
| GNU Multi-Precision Routines for SBCL | Common Lisp | |
| Ch GMP | Ch | |
| Glasgow Haskell Compiler (The implementation of Integeris basically a binding to GMP) |
Haskell | BSD |
[edit] See also
- MPFR – library for arbitrary-precision computations with correct rounding, based on GNU MP
- MPIR – a fork of GMP.
[edit] References
- ^ a b "The GNU Multiple Precision Arithmetic Library". http://gmplib.org/. Retrieved 29 October 2011.
- ^ Granlund, Torbjorn (2012-02-10). "New GMP release". gmp-announce. http://gmplib.org/list-archives/gmp-announce/2012-February/000032.html.
- ^ Future releases
- ^ http://www.mail-archive.com/kaffe@kaffe.org/msg13209.html
- ^ http://www.gnu.org/software/classpath/announce/20090205.html
- ^ The Mathematica Kernel: Issues in the Design and Implementation
- ^ The GNU Multiple Precision (GMP) Library
- ^ GCC uses the MPFR library, which in turn relies on GMP. GCC 4.3 Release Series Changes, New Features, and Fixes, last accessed 2010-01-26.
- ^ http://stackoverflow.com/questions/1017058/building-gmp-library-with-visual-studio
- ^ http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php
[edit] External links
|
|||||||||||||||||||