Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

GNU Multiple Precision Arithmetic Library

From Wikipedia, the free encyclopedia
Free software
GNU Multiple Precision Arithmetic Library
DeveloperGNU Project
Initial release1991; 34 years ago (1991)[1]
Stable release
6.3.0[2][3] Edit this on Wikidata / 30 July 2023
Repository
Written inC, (C++,assembly optionally)
TypeMathematical software
LicenseDualLGPLv3 andGPLv2[4]
Websitegmplib.org Edit this on Wikidata

GNU Multiple Precision Arithmetic Library (GMP) is afree library forarbitrary-precision arithmetic, operating onsignedintegers,rational numbers, andfloating-point numbers.[4] There are no practical limits to the precision except the ones implied by the availablememory (operands may be of up to 232−1 bits on 32-bit machines and 237 bits on 64-bit machines).[5][6] GMP has a rich set of functions, and the functions have a regular interface. The basic interface is forC, butwrappers exist for other languages, includingAda,C++,C#,Julia,.NET,OCaml,Perl,PHP,Python,R,Ruby, andRust. Prior to 2008,Kaffe, aJava virtual machine, used GMP to support Java built-in arbitrary precision arithmetic.[7] Shortly after, GMP support was added toGNU Classpath.[8]

The main target applications of GMP arecryptography applications and research, Internet security applications, andcomputer algebra systems.

GMP aims to be faster than any otherbignum library for all operand sizes. Some important factors in doing this are:

  • Fullwords are the basic type for all arithmetic.
  • Differentalgorithms are used for differentoperand sizes; algorithms which are more efficient with large numbers are not used when dealing with small numbers.
  • Assembly language (specialized for differentprocessors) is used in the most common inner loops tooptimize them as much as possible.

The first GMP release was made in 1991. It is constantly developed and maintained.[9]

GMP is part of theGNU project (although its website being off gnu.org may cause confusion), and is distributed under theGNU Lesser General Public License (LGPL).

GMP is used for integer arithmetic in manycomputer algebra systems such asMathematica[10] andMaple.[11] It is also used in theComputational Geometry Algorithms Library (CGAL).

GMP is needed to build theGNU Compiler Collection (GCC).[12]

Examples

[edit]

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

Language bindings

[edit]
Library nameLanguageLicense
GNU Multi-Precision LibraryC,C++LGPL
Math::GMPPerlLGPL
Math::GMPz,Math::GMPf andMath::GMPqPerlArtistic License v1.0 +GPL v1.0-or-later
General Multiprecision Python ProjectPythonLGPL
R package 'gmp'RGPL
The RubyGems projectRubyApache 2.0
Rust FFI bindings for GMP, MPFR and MPCRustLGPL
GNU Multi-Precision Library for PHPPHPPHP
GNU Multi-Precision Routines for SBCLArchived 2020-11-19 at theWayback MachineCommon LispPublic Domain
Ch GMPChProprietary
Parallel GMP Wrapper for BMDFM BMDFM LISP / CPublic Domain
Glasgow Haskell Compiler(The implementation ofInteger is basically a binding to GMP)HaskellBSD
luajit-gmpLuaJITMIT
gmp-wrapper-for-delphiDelphiMIT
ZarithOCamlLGPL
Math.Gmp.Native Library.NETMIT
nim-gmpNimMIT
JGMPJavaLGPL

See also

[edit]
  • GNU MPFR – 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

[edit]
  1. ^"GNU MP archive". Retrieved2018-12-03.
  2. ^Torbjörn Granlund (30 July 2023)."GMP 6.3.0 released". Retrieved30 July 2023.
  3. ^"GMP 6.3 release notes".
  4. ^ab"What is GMP?". Retrieved2014-04-07.
  5. ^Granlund, Torbjorn (2009-07-06)."Problems with mpz_set_str and huge strings". Retrieved2013-03-17.
  6. ^"GMP 6.0 News". Retrieved2019-10-04.
  7. ^Hughes, Andrew John (2008-02-28)."Removed GMP math?". Retrieved2013-03-17.
  8. ^"GNU Classpath 0.98 "Better Late Than Never"". 2009-02-05. Retrieved2013-03-17.
  9. ^"GNU MP Bignum Library". Retrieved2018-12-03.
  10. ^"The Mathematica Kernel: Issues in the Design and Implementation". October 2006. Retrieved2013-03-17.
  11. ^"The GNU Multiple Precision (GMP) Library".Maplesoft. Retrieved2013-03-17.
  12. ^GCC uses theGNU MPFR library, which in turn relies on GMP."GCC 4.3 Release Series: Changes, New Features, and Fixes". 2012-11-02. Retrieved2013-03-17.
History
Licenses
Software
Contributors
Other topics
Authority control databasesEdit this at Wikidata
Retrieved from "https://en.wikipedia.org/w/index.php?title=GNU_Multiple_Precision_Arithmetic_Library&oldid=1308868093"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp