![]() | |
Developer(s) | GNU Project |
---|---|
Initial release | 1991[1] |
Stable release | |
Repository | gmplib |
Written in | C, (C++, assembly optionally) |
Type | Mathematical software |
License | Dual LGPLv3 and GPLv2 [3] |
Website | gmplib |
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 (operands may be of up to 232−1 bits on 32-bit machines and 237 bits on 64-bit machines). [4] [5] 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#, Julia, .NET, OCaml, Perl, PHP, Python, R, Ruby, and Rust. Prior to 2008, Kaffe, a Java virtual machine, used GMP to support Java built-in arbitrary precision arithmetic. [6] Shortly after, GMP support was added to GNU Classpath. [7]
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. [8]
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 [9] and Maple. [10] It is also used in the Computational Geometry Algorithms Library (CGAL).
GMP is needed to build the GNU Compiler Collection (GCC). [11]
Here is an example of C code showing the use of the GMP library to multiply and print large numbers:
#include<stdio.h>#include<gmp.h>intmain(void){mpz_tx,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);return0;}
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<iostream>#include<gmpxx.h>intmain(){mpz_classx("7612058254738945");mpz_classy("9263591128439081");std::cout<<" "<<x<<"\n"<<"*\n"<<" "<<y<<"\n"<<"--------------------\n"<<x*y<<"\n";return0;}
Library name | Language | License |
---|---|---|
GNU Multi-Precision Library | C, C++ | LGPL |
Math::GMP | Perl | LGPL |
Math::GMPz, Math::GMPf and Math::GMPq | Perl | Artistic License v1.0 + GPL v1.0-or-later |
General Multiprecision Python Project | Python | LGPL |
R package 'gmp' | R | GPL |
The RubyGems project | Ruby | Apache 2.0 |
Rust FFI bindings for GMP, MPFR and MPC | Rust | LGPL |
GNU Multi-Precision Library for PHP | PHP | PHP |
GNU Multi-Precision Routines for SBCL | Common Lisp | Public Domain |
Ch GMP | Ch | Proprietary |
Parallel GMP Wrapper for BMDFM | BMDFM LISP / C | Public Domain |
Glasgow Haskell Compiler (The implementation of Integer is basically a binding to GMP) | Haskell | BSD |
luajit-gmp | LuaJIT | MIT |
gmp-wrapper-for-delphi | Delphi | MIT |
Zarith | OCaml | LGPL |
Math.Gmp.Native Library | .NET | MIT |
nim-gmp | Nim | MIT |
JGMP | Java | LGPL |
In computing, floating-point arithmetic (FP) is arithmetic that represents subsets of real numbers using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. Numbers of this form are called floating-point numbers. For example, 12.345 is a floating-point number in base ten with five digits of precision:
MMIX is a 64-bit reduced instruction set computing (RISC) architecture designed by Donald Knuth, with significant contributions by John L. Hennessy and Richard L. Sites. Knuth has said that,
MMIX is a computer intended to illustrate machine-level aspects of programming. In my books The Art of Computer Programming, it replaces MIX, the 1960s-style machine that formerly played such a role… I strove to design MMIX so that its machine language would be simple, elegant, and easy to learn. At the same time I was careful to include all of the complexities needed to achieve high performance in practice, so that MMIX could in principle be built and even perhaps be competitive with some of the fastest general-purpose computers in the marketplace."
In computing, NaN, standing for Not a Number, is a particular value of a numeric data type which is undefined as a number, such as the result of 0/0. Systematic use of NaNs was introduced by the IEEE 754 floating-point standard in 1985, along with the representation of other non-finite quantities such as infinities.
In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operations and directly supported by the processor. Most bitwise operations are presented as two-operand instructions where the result replaces one of the input operands.
Kaffe is a discontinued "clean room design" version 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.
In computing, especially digital signal processing, the multiply–accumulate (MAC) or multiply-add (MAD) operation is a common step that computes the product of two numbers and adds that product to an accumulator. The hardware unit that performs the operation is known as a multiplier–accumulator ; the operation itself is also often called a MAC or a MAD operation. The MAC operation modifies an accumulator a:
In computing, fixed-point is a method of representing fractional (non-integer) numbers by storing a fixed number of digits of their fractional part. Dollar amounts, for example, are often stored with exactly two fractional digits, representing the cents. More generally, the term may refer to representing fractional values as integer multiples of some fixed small unit, e.g. a fractional amount of hours as an integer multiple of ten-minute intervals. Fixed-point number representation is often contrasted to the more complicated and computationally demanding floating-point representation.
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 limited only by the available memory of the host system. This contrasts with the faster fixed-precision arithmetic found in most arithmetic logic unit (ALU) hardware, which typically offers between 8 and 64 bits of precision.
C99 is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard. It extends the previous version (C90) with new features for the language and the standard library, and helps implementations make better use of available computer hardware, such as IEEE 754-1985 floating-point arithmetic, and compiler technology. The C11 version of the C programming language standard, published in 2011, updates C99.
bc, for basic calculator, is "an arbitrary-precision calculator language" with syntax similar to the C programming language. bc is typically used as either a mathematical scripting language or as an interactive mathematical shell.
The GNU Multiple Precision Floating-Point Reliable Library is a GNU portable C library for arbitrary-precision binary floating-point computation with correct rounding, based on GNU Multi-Precision Library.
Saturation arithmetic is a version of arithmetic in which all operations, such as addition and multiplication, are limited to a fixed range between a minimum and maximum value.
Machine epsilon or machine precision is an upper bound on the relative approximation error due to rounding in floating point arithmetic. This value characterizes computer arithmetic in the field of numerical analysis, and by extension in the subject of computational science. The quantity is also called macheps and it has the symbols Greek epsilon .
In C and related programming languages, long double
refers to a floating-point data type that is often more precise than double precision though the language standard only requires it to be at least as precise as double
. As with C's other floating-point types, it may not necessarily map to an IEEE format.
Extended precision refers to floating-point number formats that provide greater precision than the basic floating-point formats. Extended precision formats support a basic format by minimizing roundoff and overflow errors in intermediate values of expressions on the base format. In contrast to extended precision, arbitrary-precision arithmetic refers to implementations of much larger numeric types using special software.
This article compares a large number of programming languages by tabulating their data types, their expression, statement, and declaration syntax, and some common operating-system interfaces.
In computing, quadruple precision is a binary floating-point–based computer number format that occupies 16 bytes with precision at least twice the 53-bit double precision.
Multiple Precision Integers and Rationals (MPIR) is an open-source software multiprecision integer library forked from the GNU Multiple Precision Arithmetic Library (GMP) project. It consists of much code from past GMP releases, and some original contributed code.