GNU Multi-Precision Library
Encyclopedia
The GNU Multiple Precision Arithmetic Library, also known as GMP, is a free
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 library for arbitrary-precision arithmetic
Arbitrary-precision arithmetic
In computer science, arbitrary-precision arithmetic indicates that calculations are performed on numbers whose digits of precision are limited only by the available memory of the host system. This contrasts with the faster fixed-precision arithmetic found in most ALU hardware, which typically...

, operating on signed integer
Integer
The integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively...

s, rational numbers, and floating point
Floating point
In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

 numbers. There are no practical limits to the precision except the ones implied by the available memory
Virtual memory
In computing, virtual memory is a memory management technique developed for multitasking kernels. This technique virtualizes a computer architecture's various forms of computer data storage , allowing a program to be designed as though there is only one kind of memory, "virtual" memory, which...

 in the machine GMP runs on (operand dimension limit is 231 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
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 but wrappers exist for other languages including C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, C#, OCaml, Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

, PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

, and Python. In the past, the Kaffe
Kaffe
Kaffe is a clean room design of a Java Virtual Machine. It comes with a subset of the Java Platform, Standard Edition , Java API, and tools needed to provide a Java runtime environment. Like most other Free Java virtual machines, Kaffe uses GNU Classpath as its class library.Kaffe, first released...

 Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 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. As a result, GMP support has been added to GNU Classpath
GNU Classpath
GNU Classpath is a project aiming to create a free software implementation of the standard class library for the Java programming language. Despite the massive size of the library to be created, the majority of the task is already done, including Swing, CORBA, and other major parts. The Classpath...

.

The main target applications of GMP are cryptography
Cryptography
Cryptography is the practice and study of techniques for secure communication in the presence of third parties...

 applications and research, Internet security applications, and computer algebra system
Computer algebra system
A computer algebra system is a software program that facilitates symbolic mathematics. The core functionality of a CAS is manipulation of mathematical expressions in symbolic form.-Symbolic manipulations:...

s.

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 algorithm
    Algorithm
    In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning...

    s for different operand
    Operand
    In mathematics, an operand is the object of a mathematical operation, a quantity on which an operation is performed.-Example :The following arithmetic expression shows an example of operators and operands:3 + 6 = 9\;...

     sizes. The algorithms that are fastest for really big numbers are seldom fastest for small numbers.
  • Highly optimized
    Optimization (computer science)
    In computer science, program optimization or software optimization is the process of modifying a software system to make some aspect of it work more efficiently or use fewer resources...

     assembly code for the most important inner loop
    Inner loop
    In computer programs, an important form of control flow is the loop. For example, this small pseudo-code program uses two nested loops to iterate over all the entries of an n×n matrix, changing their values so that the matrix becomes an identity matrix: for a in 1..n for b in 1..n ...

    s, specialized for different processors
    Central processing unit
    The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...

    .


The first GMP release was made in 1991. It is continually developed and maintained. The current release is 5.0.2.

GMP is part of the GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 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
Mathematica
Mathematica is a computational software program used in scientific, engineering, and mathematical fields and other areas of technical computing...

 and Maple
Maple (software)
Maple is a general-purpose commercial computer algebra system. It was first developed in 1980 by the Symbolic Computation Group at the University of Waterloo in Waterloo, Ontario, Canada....

.

GMP is required for building GCC
GNU Compiler Collection
The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain...

.

Example

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

  1. include
  2. include
  3. include


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


Criticism

GMP has been criticized for its perceived lackluster support of Microsoft Windows and Microsoft Visual Studio
Microsoft Visual Studio
Microsoft Visual Studio is an integrated development environment from Microsoft. It is used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all...

.

Language bindings

Library Name Language License
GNU Multi-Precision Library C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 / C++
LGPL
GNU Lesser General Public License
The GNU Lesser General Public License or LGPL is a free software license published by the Free Software Foundation . It was designed as a compromise between the strong-copyleft GNU General Public License or GPL and permissive licenses such as the BSD licenses and the MIT License...

Math::GMP Perl
GNU Multi-Precision Library for .NET C# / .NET
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...

LGPL
GNU Lesser General Public License
The GNU Lesser General Public License or LGPL is a free software license published by the Free Software Foundation . It was designed as a compromise between the strong-copyleft GNU General Public License or GPL and permissive licenses such as the BSD licenses and the MIT License...

General Multiprecision Python Project Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

The RubyGems project Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

GNU Multi-Precision Library for PHP PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

PHP License
GNU Multi-Precision Routines for SBCL Common Lisp
Common Lisp
Common Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in ANSI standard document ANSI INCITS 226-1994 , . From the ANSI Common Lisp standard the Common Lisp HyperSpec has been derived for use with web browsers...

Ch GMP Ch
Ch (computer programming)
In computing, Ch is a proprietary cross-platform C and C++ interpreter originally designed by Dr. Harry H. Cheng as a scripting language for beginners to learn math, computing, numerics, and programming in C/C++...

Glasgow Haskell Compiler
Glasgow Haskell Compiler
The Glorious Glasgow Haskell Compilation System, more commonly known as the Glasgow Haskell Compiler or GHC, is an open source native code compiler for the functional programming language Haskell. The lead developers are Simon Peyton Jones and Simon Marlow...


(The implementation of Integer
is basically a binding to GMP)
Haskell
Haskell (programming language)
Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...

BSD

See also

  • MPFR
    MPFR
    GNU MPFR is a portable C library for arbitrary-precision binary floating-point computation with correct rounding, based on GNU Multi-Precision Library. The computation is both efficient and has a well-defined semantics. It copies the ideas from the ANSI/IEEE-754 standard for fixed-precision...

     – library for arbitrary-precision computations with correct rounding, based on GNU MP
  • MPIR
    MPIR (mathematics software)
    MPIR - Multiple Precision Integers and Rationals is an open source multiprecision integer library forked from the GMP project. It consists of much code from past GMP releases, in combination with much original contributed code....

    – a fork of GMP.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK