GMP (library)
   HOME

TheInfoList



OR:

GNU Multiple Precision Arithmetic Library (GMP) is a
free Free may refer to: Concept * Freedom, having the ability to do something, without having to obey anyone/anything * Freethought, a position that beliefs should be formed only on the basis of logic, reason, and empiricism * Emancipate, to procur ...
library for arbitrary-precision arithmetic, operating on signed integers, rational numbers, and
floating-point numbers In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be ...
. 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). 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 Ada may refer to: Places Africa * Ada Foah, a town in Ghana * Ada (Ghana parliament constituency) * Ada, Osun, a town in Nigeria Asia * Ada, Urmia, a village in West Azerbaijan Province, Iran * Ada, Karaman, a village in Karaman Province, Tur ...
, C++, C#, Julia, .NET,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, Perl, PHP, Python, R, Ruby, and Rust. Prior to 2008,
Kaffe Kaffe is a discontinued "clean room design" (reverse engineering) version of a Java Virtual Machine. It comes with a subset of the Java Platform, Standard Edition (Java SE), Java API, and tools needed to provide a Java runtime environment. Like m ...
, a
Java virtual machine A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes ...
, used GMP to support Java built-in arbitrary precision arithmetic. Shortly after, GMP support was added to GNU Classpath. 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 In computer science, arbitrary-precision arithmetic, also called bignum arithmetic, multiple-precision arithmetic, or sometimes infinite-precision arithmetic, indicates that calculations are performed on numbers whose digits of precision are li ...
library for all operand sizes. Some important factors in doing this are: * Using full words as the basic arithmetic type. * Using different algorithms for different operand sizes; algorithms that are faster for very big numbers are usually slower for small numbers. * Highly optimized
assembly language In computer programming, assembly language (or assembler language, or symbolic machine code), often referred to simply as Assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence be ...
code for the most important inner loops, specialized for different processors. The first GMP release was made in 1991. It is constantly developed and maintained. 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 Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimizat ...
and Maple. It is also used in the
Computational Geometry Algorithms Library The Computational Geometry Algorithms Library (CGAL) is an open source software library of computational geometry algorithms. While primarily written in C++, Scilab bindings and bindings generated with SWIG (supporting Python and Java for now) ...
(CGAL). GMP is needed to build the GNU Compiler Collection (GCC).GCC uses the
GNU MPFR The GNU Multiple Precision Floating-Point Reliable Library (GNU MPFR) is a GNU portable C library for arbitrary-precision binary floating-point computation with correct rounding, based on GNU Multi-Precision Library. Library MPFR's computatio ...
library, which in turn relies on GMP.


Examples

Here is an example of C code showing the use of the GMP library to multiply and print large numbers: #include #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.) #include #include int main()


Language bindings


See also

*
GNU MPFR The GNU Multiple Precision Floating-Point Reliable Library (GNU MPFR) is a GNU portable C library for arbitrary-precision binary floating-point computation with correct rounding, based on GNU Multi-Precision Library. Library MPFR's computatio ...
– a library for arbitrary-precision computations with correct rounding, based on GNU MP * CLN – a class library for arbitrary precision * MPIR – a fork of GMP, not maintained any more


References


External links

* {{DEFAULTSORT:Gnu Multi-Precision Library Assembly language software C (programming language) libraries Computer arithmetic Free software programmed in C Multiple Precision Arithmetic Library Numerical libraries Software using the LGPL license