HOME

TheInfoList




GNU Multiple Precision Arithmetic Library (GMP) is a
free Free may refer to: Concept * Freedom, having the ability to act or change without constraint * Emancipate, to procure political rights, as for a disenfranchised group * Free will, control exercised by rational agents over their actions and decis ...

free
library for
arbitrary-precision arithmetic 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 numerical digit, digits of pre ...
, operating on
signed Signing may refer to: * Using sign language * Signature, placing one's name on a document * Signature (disambiguation) * Manual communication, signing as a form of communication using the hands in place of the voice * Digital signature, signing as ...
integer An integer (from the Latin Latin (, or , ) is a classical language A classical language is a language A language is a structured system of communication Communication (from Latin ''communicare'', meaning "to share" or "to ...
s,
rational numbers In mathematics Mathematics (from Greek: ) includes the study of such topics as numbers (arithmetic and number theory), formulas and related structures (algebra), shapes and spaces in which they are contained (geometry), and quantities a ...
, and
floating-point numbers In computing, floating-point arithmetic (FP) is arithmetic using formulaic representation of real numbers as an approximation to support a trade-off between range and precision. For this reason, floating-point computation is often used in syste ...
. There are no practical limits to the precision except the ones implied by the available
memory Memory is the faculty of the brain A brain is an organ Organ may refer to: Biology * Organ (anatomy) An organ is a group of Tissue (biology), tissues with similar functions. Plant life and animal life rely on many organs that co-exis ...

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 Ada Foah is a town on the southeast coast of Ghana, where the Volta River meets the Atlantic Ocean. The town is located along the Volta River, off of the Accra-Aflao motorway. Known for Palm tree, pal ...
,
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

C++
, C#,
Julia Julia is usually a feminine given name. It is a Latinate feminine form of the name Julio (given name), Julio and Julius. (For further details on etymology, see the wikt:Iulius#Latin, Wiktionary entry "Julius".) The given name ''Julia'' had been ...
,
.NET The domain name A domain name is an identification string String or strings may refer to: *String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects Arts, enterta ...
,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose, multi-paradigm programming language Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. S ...
,
Perl Perl is a family of two high-level High-level and low-level, as technical terms, are used to classify, describe and point to specific Objective (goal), goals of a systematic operation; and are applied in a wide range of contexts, such as, for ...
,
PHP PHP is a general-purpose scripting language A scripting language or script language is a programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various k ...

PHP
,
Python Python may refer to: * Pythonidae The Pythonidae, commonly known as pythons, are a family of nonvenomous snakes found in Africa, Asia, and Australia. Among its members are some of the largest snakes in the world. Ten genera and 42 species ...
, R,
Ruby A ruby is a pink-ish red to blood-red colored gemstone A gemstone (also called a fine gem, jewel, precious stone, or semi-precious stone) is a piece of mineral In geology and mineralogy, a mineral or mineral species is, broadly spea ...
, and
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous ferric oxides, hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxi ...
. Prior to 2008,
Kaffe Kaffe is a discontinued "clean room design Clean-room design (also known as the Chinese wall technique) is the method of copying a design by reverse engineering and then recreating it without infringing any of the copyright Copyright is ...

Kaffe
, a Java virtual machine, used GMP to support Java built-in arbitrary precision arithmetic. Shortly after, GMP support was added to
GNU Classpath GNU Classpath is a free software Free software (or libre software) is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any adapted versions. Free ...
. The main target applications of GMP are
cryptography Cryptography, or cryptology (from grc, , translit=kryptós "hidden, secret"; and ''graphein'', "to write", or ''-logia ''-logy'' is a suffix in the English language, used with words originally adapted from Ancient Greek ending in (''- ...

cryptography
applications and research, Internet security applications, and
computer algebra system A computer algebra system (CAS) or symbolic algebra system (SAS) is any mathematical software Mathematical software is software used to mathematical model, model, analyze or calculate numeric, symbolic or geometric data. It is a type of applica ...

computer algebra system
s. GMP aims to be faster than any other
bignum In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of comp ...
library for all operand sizes. Some important factors in doing this are: * Using full
words In linguistics Linguistics is the scientific study of language A language is a structured system of communication used by humans, including speech (spoken language), gestures (Signed language, sign language) and writing. Most lang ...
as the basic arithmetic type. * Using different
algorithm In and , an algorithm () is a finite sequence of , computer-implementable instructions, typically to solve a class of problems or to perform a computation. Algorithms are always and are used as specifications for performing s, , , and other ...

algorithm
s for different
operand In mathematics an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on. Example The following arithmetic expression shows an example of operators and operands: :3 + 6 = 9 In the above example ...
sizes; algorithms that are faster for very big numbers are usually slower for small numbers. * Highly optimized
assembly language In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, gene ...
code for the most important
inner loop In computer programs, an important form of control flow is the Loop (computing), loop which causes a block of code to be executed more than once. A common idiom is to have a loop Nested loop, nested inside another loop, with the contained loop be ...
s, specialized for different
processors A central processing unit (CPU), also called a central processor, main processor or just Processor (computing), processor, is the electronic circuitry that executes Instruction (computing), instructions comprising a computer program. The CPU per ...

processors
. The first GMP release was made in 1991. It is constantly developed and maintained. GMP is part of the
GNU GNU () is an extensive collection of free software Free software (or libre software) is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any ...

GNU
project (although its website being off gnu.org may cause confusion), and is distributed under the
GNU Lesser General Public License The GNU Lesser General Public License (LGPL) is a free-software license A free-software license is a notice that grants the recipient of a piece of software extensive rights to modify and redistribute that software. These actions are usual ...
(LGPL). GMP is used for integer arithmetic in many
computer algebra system A computer algebra system (CAS) or symbolic algebra system (SAS) is any mathematical software Mathematical software is software used to mathematical model, model, analyze or calculate numeric, symbolic or geometric data. It is a type of applica ...

computer algebra system
s such as
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning Machine learning (ML) is the study of computer algorithms that can improve automatically through experi ...

Mathematica
and
Maple ''Acer'' is a genus Genus /ˈdʒiː.nəs/ (plural genera /ˈdʒen.ər.ə/) is a taxonomic rank In biological classification In biology, taxonomy () is the scientific study of naming, defining (Circumscription (taxonomy), circumscr ...
. It is also used in the Computational Geometry Algorithms Library (CGAL) because geometry algorithms tend to 'explode' when using ordinary floating-point CPU math. GMP is needed to build the
GNU Compiler Collection The GNU Compiler Collection (GCC) is an optimizing compiler In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithm of an ...
(GCC).GCC uses the
GNU MPFR The GNU Multiple Precision Floating-Point Reliable Library (GNU MPFR) is a GNU GNU () is an extensive collection of free software, which can be used as an operating system or can be used in parts with other operating systems. The use of the c ...
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 GNU () is an extensive collection of free software, which can be used as an operating system or can be used in parts with other operating systems. The use of the c ...
– 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 with a mostly compatible interface, which aims to provide an MSVC-based compilation system for Microsoft Windows platforms


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