fbpx
维基百科

GNU多重精度运算库

GNU多重精度运算库(英語:GNU Multiple Precision Arithmetic Library,简称GMP或gmpal)是一个开源的任意精度运算库,支持正负数的整数有理数浮点数。它没有任何精度限制,只受限于可用内存。GMP有很多函数,它们都有一个规则的接口。它是C语言写成的,但用为其他很多语言做包装,包括AdaC++C#OCamlPerlPHPpythonR。GMP主要运用于加密应用和研究、互联网安全应用、计算机代数系统和计算代数研究。GMP的目标是成为最快的大数运算库,GMP是GNU项目的一部分,它在GNU宽通用公共许可证下发表。GMP在许多计算机辅助代数系统中用于整数运算,如MathematicaMaple。GMP需要使用GCCGNU编译器套装)编译。

GNU Multiple Precision Arithmetic Library
開發者GNU计划
首次发布1991年 (1991)[1]
当前版本
  • 6.3.0 (2023年7月30日;穩定版本)[2]
源代码库
  • gmplib.org/repo/
编程语言C语言
操作系统跨平台
类型数学软件
许可协议LGPL
网站gmplib.org

示例 编辑

这是一个C语言示例,它展示了如何使用GMP做乘法运算并输出。

#include <stdio.h> #include <stdlib.h> #include <gmp.h> 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);  /* free used memory释放内存*/   mpz_clear(x);  mpz_clear(y);  mpz_clear(result);  return EXIT_SUCCESS; } 

这段代码计算7612058254738945和9263591128439081的乘积。

编译运行,获得这样的输出:(在UNIX类系统上,需要 -lgmp)

 7612058254738945 * 9263591128439081 -------------------- 70514995317761165008628990709545 

我们可以使用C++完成相同的运算。(如果在类Unix系统下编译,需要使用 -lgmpxx -lgmp)

#include <iostream> #include <gmpxx.h> int main() {  mpz_class x("7612058254738945");  mpz_class y("9263591128439081");  std::cout << "\n " << x << "\n*\n " << y;  std::cout << "\n--------------------\n" << x * y << "\n\n"; } 

语言支持 编辑

Library name 语言 许可证
GNU Multi-Precision Library (页面存档备份,存于互联网档案馆 C, C++ LGPL
Math::GMP (页面存档备份,存于互联网档案馆 Perl
C#, .NET LGPL
General Multiprecision Python Project (页面存档备份,存于互联网档案馆 Python
The RubyGems project (页面存档备份,存于互联网档案馆 Ruby
GNU Multi-Precision Library for PHP (页面存档备份,存于互联网档案馆 PHP PHP
GNU Multi-Precision Routines for SBCL (页面存档备份,存于互联网档案馆 Common Lisp
Ch GMP(页面存档备份,存于互联网档案馆 Ch (计算机语言)英语Ch_(computer_programming)
Glasgow Haskell Compiler
(The implementation of Integer
is basically a binding to GMP)
Haskell BSD

参考资料 编辑

  1. ^ The GNU Multiple Precision Arithmetic Library. [29 October 2011]. (原始内容于2021-01-28). 
  2. ^ 2.0 2.1 "GMP 6.3.0 released"; 作者姓名字符串: Torbjörn Granlund; 作品或名稱語言: 英語; 出版日期: 2023年7月30日; 检索日期: 2023年7月30日.

外部链接 编辑

gnu多重精度运算库, 英語, multiple, precision, arithmetic, library, 简称gmp或gmpal, 是一个开源的任意精度运算库, 支持正负数的整数, 有理数, 浮点数, 它没有任何精度限制, 只受限于可用内存, gmp有很多函数, 它们都有一个规则的接口, 它是c语言写成的, 但用为其他很多语言做包装, 包括ada, ocaml, perl, python, gmp主要运用于加密应用和研究, 互联网安全应用, 计算机代数系统和计算代数研究, gmp的目标是成为最快的大数运算. GNU多重精度运算库 英語 GNU Multiple Precision Arithmetic Library 简称GMP或gmpal 是一个开源的任意精度运算库 支持正负数的整数 有理数 浮点数 它没有任何精度限制 只受限于可用内存 GMP有很多函数 它们都有一个规则的接口 它是C语言写成的 但用为其他很多语言做包装 包括Ada C C OCaml Perl PHP python 和 R GMP主要运用于加密应用和研究 互联网安全应用 计算机代数系统和计算代数研究 GMP的目标是成为最快的大数运算库 GMP是GNU项目的一部分 它在GNU宽通用公共许可证下发表 GMP在许多计算机辅助代数系统中用于整数运算 如Mathematica和Maple GMP需要使用GCC GNU编译器套装 编译 GNU Multiple Precision Arithmetic Library開發者GNU计划首次发布1991年 1991 1 当前版本6 3 0 2023年7月30日 穩定版本 2 源代码库gmplib wbr org wbr repo wbr 编程语言C语言操作系统跨平台类型数学软件许可协议LGPL网站gmplib wbr org 目录 1 示例 2 语言支持 3 参考资料 4 外部链接示例 编辑这是一个C语言示例 它展示了如何使用GMP做乘法运算并输出 include lt stdio h gt include lt stdlib h gt include lt gmp h gt 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 free used memory释放内存 mpz clear x mpz clear y mpz clear result return EXIT SUCCESS 这段代码计算7612058254738945和9263591128439081的乘积 编译运行 获得这样的输出 在UNIX类系统上 需要 lgmp 7612058254738945 9263591128439081 70514995317761165008628990709545 我们可以使用C 完成相同的运算 如果在类Unix系统下编译 需要使用 lgmpxx lgmp include lt iostream gt include lt gmpxx h gt int main mpz class x 7612058254738945 mpz class y 9263591128439081 std cout lt lt n lt lt x lt lt n n lt lt y std cout lt lt n n lt lt x y lt lt n n 语言支持 编辑Library name 语言 许可证GNU Multi Precision Library 页面存档备份 存于互联网档案馆 C C LGPLMath GMP 页面存档备份 存于互联网档案馆 PerlGNU Multi Precision Library for NET C NET LGPLGeneral Multiprecision Python Project 页面存档备份 存于互联网档案馆 PythonThe RubyGems project 页面存档备份 存于互联网档案馆 RubyGNU Multi Precision Library for PHP 页面存档备份 存于互联网档案馆 PHP PHPGNU Multi Precision Routines for SBCL 页面存档备份 存于互联网档案馆 Common LispCh GMP 页面存档备份 存于互联网档案馆 Ch 计算机语言 英语 Ch computer programming Glasgow Haskell Compiler The implementation of Integeris basically a binding to GMP Haskell BSD参考资料 编辑 The GNU Multiple Precision Arithmetic Library 29 October 2011 原始内容存档于2021 01 28 2 0 2 1 GMP 6 3 0 released 作者姓名字符串 Torbjorn Granlund 作品或名稱語言 英語 出版日期 2023年7月30日 检索日期 2023年7月30日 外部链接 编辑gmplib官方主页 页面存档备份 存于互联网档案馆 取自 https zh wikipedia org w index php title GNU多重精度运算库 amp oldid 76488824, 维基百科,wiki,书籍,书籍,图书馆,

文章

,阅读,下载,免费,免费下载,mp3,视频,mp4,3gp, jpg,jpeg,gif,png,图片,音乐,歌曲,电影,书籍,游戏,游戏。