Knowledge

GNU Multiple Precision Arithmetic Library

Source 📝

1487: 88: 38: 218:(operands may be of up to 2−1 bits on 32-bit machines and 2 bits on 64-bit machines). GMP has a rich set of functions, and the functions have a regular interface. The basic interface is for 1894: 1925: 17: 368: 1950: 1564: 1935: 1557: 1612: 1920: 1602: 1597: 1552: 1189: 995: 901: 884: 349: 158: 140: 1547: 334: 1607: 1084: 235: 196: 1404: 1940: 1514: 1118: 943: 259: 282:, used GMP to support Java built-in arbitrary precision arithmetic. Shortly after, GMP support was added to 1945: 1930: 1882: 323:
sizes; algorithms which are more efficient with large numbers are not used when dealing with small numbers.
239: 101: 1215: 1184: 990: 973: 271: 267: 79: 1580: 1167: 1101: 930: 227: 162: 1257: 1209: 1041: 386:
Here is an example of C code showing the use of the GMP library to multiply and print large numbers:
211: 1728: 1542: 1425: 1070: 958: 875: 348:
project (although its website being off gnu.org may cause confusion), and is distributed under the
263: 219: 124: 87: 1302: 1673: 1343: 375: 356: 330: 294: 1363: 1841: 1733: 1063: 1029: 662:
7612058254738945 * 9263591128439081 -------------------- 70514995317761165008628990709545
1856: 1585: 145: 1808: 1113: 1046: 279: 214:. There are no practical limits to the precision except the ones implied by the available 8: 1899: 1743: 953: 1486: 1831: 1663: 1658: 1590: 1206:– a library for arbitrary-precision computations with correct rounding, based on GNU MP 207: 200: 1851: 1758: 1653: 1507: 1145: 326: 132: 1454: 1249: 1866: 1798: 926: 364: 341:
The first GMP release was made in 1991. It is constantly developed and maintained.
309: 223: 152: 1836: 1826: 1703: 666:
For comparison, one can write instead the following equivalent C++ program. (The
1846: 1748: 1150: 978: 243: 215: 1914: 1888: 1668: 1537: 1019: 283: 192: 1861: 1683: 1678: 1632: 1500: 1236: 1089: 290: 1096: 1713: 1643: 1523: 1172: 1155: 1123: 1106: 1024: 1012: 360: 304:
library for all operand sizes. Some important factors in doing this are:
50: 1773: 1767: 1718: 1179: 1162: 651:
This code calculates the value of 7612058254738945 × 9263591128439081.
45: 916: 912: 908: 1793: 1723: 1708: 1429: 985: 891: 316: 1803: 1783: 1763: 1688: 1638: 1449: 1203: 1130: 938: 1693: 1405:"The Mathematica Kernel: Issues in the Design and Implementation" 1322: 320: 203: 1036: 968: 1788: 1778: 1753: 301: 293:
applications and research, Internet security applications, and
1492: 1648: 1135: 1058: 879: 275: 247: 231: 128: 1698: 1281: 921: 896: 654:
Compiling and running this program gives this result. (The
251: 107: 1455:"GCC 4.3 Release Series: Changes, New Features, and Fixes" 1002: 37: 1628: 1007: 345: 255: 1384: 870: 1480: 173: 1053: 670:flags are used if compiling on Unix-type systems.) 1255: 658:flag is used if compiling on Unix-type systems.) 1912: 1895:Free Software Foundation anti-Windows campaigns 1508: 1364:"GNU Classpath 0.98 "Better Late Than Never"" 1303:"Problems with mpz_set_str and huge strings" 333:) is used in the most common inner loops to 355:GMP is used for integer arithmetic in many 1515: 1501: 1485: 1426:"The GNU Multiple Precision (GMP) Library" 86: 36: 1212:– a class library for arbitrary precision 369:Computational Geometry Algorithms Library 185:GNU Multiple Precision Arithmetic Library 31:GNU Multiple Precision Arithmetic Library 1300: 1218:– a fork of GMP, not maintained any more 289:The main target applications of GMP are 986:Rust FFI bindings for GMP, MPFR and MPC 14: 1913: 1452:library, which in turn relies on GMP. 1341: 1276: 1274: 312:are the basic type for all arithmetic. 1496: 1020:GNU Multi-Precision Routines for SBCL 939:General Multiprecision Python Project 300:GMP aims to be faster than any other 226:exist for other languages, including 1613:GNAT Modified General Public License 851: 1377: 1271: 1003:GNU Multi-Precision Library for PHP 24: 1926:C (programming language) libraries 1342:Hughes, Andrew John (2008-02-28). 1256:Torbjörn Granlund (30 July 2023). 25: 1962: 1603:GNU Affero General Public License 1598:GNU Lesser General Public License 1472: 1301:Granlund, Torbjorn (2009-07-06). 350:GNU Lesser General Public License 1951:Software using the LGPL license 1522: 1442: 1418: 1608:GNU Free Documentation License 1397: 1356: 1335: 1315: 1294: 1229: 1080:is basically a binding to GMP) 1054:Parallel GMP Wrapper for BMDFM 197:arbitrary-precision arithmetic 13: 1: 1936:Free software programmed in C 1222: 1883:GNU/Linux naming controversy 723:"9263591128439081" 708:"7612058254738945" 478:"9263591128439081" 454:"7612058254738945" 7: 1197: 871:GNU Multi-Precision Library 381: 374:GMP is needed to build the 329:(specialized for different 62:; 33 years ago 18:GNU Multi-Precision Library 10: 1967: 1921:Assembly language software 1581:GNU General Public License 801:"-------------------- 559:"-------------------- 1875: 1819: 1621: 1573: 1530: 367:. It is also used in the 337:them as much as possible. 168: 151: 139: 120: 100: 96: 78: 74: 56: 44: 35: 1565:History of free software 1543:Free Software Foundation 1071:Glasgow Haskell Compiler 672: 660: 388: 357:computer algebra systems 295:computer algebra systems 1385:"GNU MP Bignum Library" 1146:Math.Gmp.Native Library 1075:(The implementation of 376:GNU Compiler Collection 319:are used for different 1114:gmp-wrapper-for-delphi 598:/* free used memory */ 212:floating-point numbers 146:Mathematical software 1941:GNU Project software 1258:"GMP 6.3.0 released" 969:The RubyGems project 280:Java virtual machine 1946:Numerical libraries 1931:Computer arithmetic 1900:Defective by Design 1867:Richard M. Stallman 1344:"Removed GMP math?" 344:GMP is part of the 32: 1832:Benjamin Mako Hill 30: 1908: 1907: 1852:Georg C. F. Greve 1759:GNU Privacy Guard 1586:linking exception 1195: 1194: 1081: 852:Language bindings 327:Assembly language 274:. Prior to 2008, 182: 181: 16:(Redirected from 1958: 1517: 1510: 1503: 1494: 1493: 1489: 1484: 1483: 1481:Official website 1466: 1465: 1463: 1462: 1446: 1440: 1439: 1437: 1436: 1422: 1416: 1415: 1413: 1412: 1401: 1395: 1394: 1392: 1391: 1381: 1375: 1374: 1372: 1371: 1360: 1354: 1353: 1351: 1350: 1339: 1333: 1332: 1330: 1329: 1319: 1313: 1312: 1310: 1309: 1298: 1292: 1291: 1289: 1288: 1278: 1269: 1268: 1266: 1264: 1253: 1247: 1246: 1244: 1243: 1237:"GNU MP archive" 1233: 1078: 1074: 927:Artistic License 856: 855: 847: 844: 841: 838: 835: 832: 829: 826: 823: 820: 817: 814: 811: 808: 805: 802: 799: 796: 793: 790: 787: 784: 781: 778: 777:" " 775: 772: 769: 766: 763: 760: 757: 754: 751: 748: 745: 742: 741:" " 739: 736: 733: 730: 727: 724: 721: 718: 715: 712: 709: 706: 703: 700: 697: 694: 691: 688: 685: 682: 679: 678:<iostream> 676: 669: 657: 647: 644: 641: 638: 635: 632: 629: 626: 623: 620: 617: 614: 611: 608: 605: 602: 599: 596: 593: 590: 587: 584: 581: 578: 575: 572: 569: 566: 563: 560: 557: 554: 551: 548: 545: 542: 539: 536: 533: 530: 527: 524: 521: 518: 515: 512: 509: 506: 503: 500: 497: 494: 491: 488: 485: 482: 479: 476: 473: 470: 467: 466:mpz_init_set_str 464: 461: 458: 455: 452: 449: 446: 443: 442:mpz_init_set_str 440: 437: 434: 431: 428: 425: 422: 419: 416: 413: 410: 407: 404: 401: 398: 395: 392: 208:rational numbers 178: 175: 116: 113: 111: 109: 90: 70: 68: 63: 40: 33: 29: 21: 1966: 1965: 1961: 1960: 1959: 1957: 1956: 1955: 1911: 1910: 1909: 1904: 1871: 1837:Bradley M. Kuhn 1827:Alexandre Oliva 1815: 1617: 1569: 1526: 1521: 1479: 1478: 1475: 1470: 1469: 1460: 1458: 1453: 1447: 1443: 1434: 1432: 1424: 1423: 1419: 1410: 1408: 1403: 1402: 1398: 1389: 1387: 1383: 1382: 1378: 1369: 1367: 1362: 1361: 1357: 1348: 1346: 1340: 1336: 1327: 1325: 1321: 1320: 1316: 1307: 1305: 1299: 1295: 1286: 1284: 1280: 1279: 1272: 1262: 1260: 1254: 1250: 1241: 1239: 1235: 1234: 1230: 1225: 1200: 1079: 1076: 1073: 954:R package 'gmp' 854: 849: 848: 845: 842: 839: 836: 833: 830: 827: 824: 821: 818: 815: 812: 809: 806: 803: 800: 797: 794: 791: 788: 785: 782: 779: 776: 773: 770: 767: 764: 761: 758: 755: 752: 749: 746: 743: 740: 737: 734: 731: 728: 725: 722: 719: 716: 713: 710: 707: 704: 701: 698: 695: 692: 689: 686: 684:<gmpxx.h> 683: 680: 677: 674: 667: 664: 663: 655: 649: 648: 645: 642: 639: 636: 633: 630: 627: 624: 621: 618: 615: 612: 609: 606: 603: 600: 597: 594: 591: 588: 585: 582: 579: 576: 573: 570: 567: 564: 561: 558: 555: 552: 549: 546: 543: 540: 537: 534: 531: 528: 525: 522: 519: 516: 513: 510: 507: 504: 501: 498: 495: 492: 489: 486: 483: 480: 477: 474: 471: 468: 465: 462: 459: 456: 453: 450: 447: 444: 441: 438: 435: 432: 429: 426: 423: 420: 417: 414: 411: 408: 405: 402: 399: 396: 394:<stdio.h> 393: 390: 384: 199:, operating on 172: 106: 92: 66: 64: 61: 57:Initial release 28: 23: 22: 15: 12: 11: 5: 1964: 1954: 1953: 1948: 1943: 1938: 1933: 1928: 1923: 1906: 1905: 1903: 1902: 1897: 1892: 1885: 1879: 1877: 1873: 1872: 1870: 1869: 1864: 1859: 1854: 1849: 1847:Federico Heinz 1844: 1839: 1834: 1829: 1823: 1821: 1817: 1816: 1814: 1813: 1806: 1801: 1796: 1791: 1786: 1781: 1776: 1771: 1761: 1756: 1751: 1749:GNU Archimedes 1746: 1741: 1736: 1731: 1726: 1721: 1716: 1711: 1706: 1701: 1696: 1691: 1686: 1681: 1676: 1671: 1666: 1661: 1656: 1651: 1646: 1641: 1636: 1625: 1623: 1619: 1618: 1616: 1615: 1610: 1605: 1600: 1595: 1594: 1593: 1591:font exception 1588: 1577: 1575: 1571: 1570: 1568: 1567: 1562: 1561: 1560: 1555: 1550: 1540: 1534: 1532: 1528: 1527: 1520: 1519: 1512: 1505: 1497: 1491: 1490: 1474: 1473:External links 1471: 1468: 1467: 1441: 1417: 1407:. October 2006 1396: 1376: 1355: 1334: 1323:"GMP 6.0 News" 1314: 1293: 1282:"What is GMP?" 1270: 1248: 1227: 1226: 1224: 1221: 1220: 1219: 1213: 1207: 1199: 1196: 1193: 1192: 1187: 1182: 1176: 1175: 1170: 1165: 1159: 1158: 1153: 1148: 1142: 1141: 1138: 1133: 1127: 1126: 1121: 1116: 1110: 1109: 1104: 1099: 1093: 1092: 1087: 1082: 1067: 1066: 1061: 1059:BMDFM LISP / C 1056: 1050: 1049: 1044: 1039: 1033: 1032: 1027: 1022: 1016: 1015: 1010: 1005: 999: 998: 993: 988: 982: 981: 976: 971: 965: 964: 961: 956: 950: 949: 946: 941: 935: 934: 933:v1.0-or-later 924: 919: 905: 904: 899: 894: 888: 887: 882: 873: 867: 866: 863: 860: 853: 850: 673: 661: 389: 383: 380: 339: 338: 324: 313: 180: 179: 170: 166: 165: 155: 149: 148: 143: 137: 136: 122: 118: 117: 104: 98: 97: 94: 93: 91:/ 30 July 2023 84: 82: 80:Stable release 76: 75: 72: 71: 58: 54: 53: 48: 42: 41: 26: 9: 6: 4: 3: 2: 1963: 1952: 1949: 1947: 1944: 1942: 1939: 1937: 1934: 1932: 1929: 1927: 1924: 1922: 1919: 1918: 1916: 1901: 1898: 1896: 1893: 1891: 1890: 1889:Revolution OS 1886: 1884: 1881: 1880: 1878: 1874: 1868: 1865: 1863: 1860: 1858: 1857:John Sullivan 1855: 1853: 1850: 1848: 1845: 1843: 1840: 1838: 1835: 1833: 1830: 1828: 1825: 1824: 1822: 1818: 1812: 1811: 1807: 1805: 1802: 1800: 1797: 1795: 1792: 1790: 1787: 1785: 1782: 1780: 1777: 1775: 1772: 1769: 1765: 1762: 1760: 1757: 1755: 1752: 1750: 1747: 1745: 1742: 1740: 1737: 1735: 1732: 1730: 1727: 1725: 1722: 1720: 1717: 1715: 1712: 1710: 1707: 1705: 1702: 1700: 1697: 1695: 1692: 1690: 1687: 1685: 1682: 1680: 1677: 1675: 1672: 1670: 1667: 1665: 1662: 1660: 1657: 1655: 1652: 1650: 1647: 1645: 1642: 1640: 1637: 1634: 1630: 1627: 1626: 1624: 1620: 1614: 1611: 1609: 1606: 1604: 1601: 1599: 1596: 1592: 1589: 1587: 1584: 1583: 1582: 1579: 1578: 1576: 1572: 1566: 1563: 1559: 1558:Latin America 1556: 1554: 1551: 1549: 1546: 1545: 1544: 1541: 1539: 1538:GNU Manifesto 1536: 1535: 1533: 1529: 1525: 1518: 1513: 1511: 1506: 1504: 1499: 1498: 1495: 1488: 1482: 1477: 1476: 1456: 1451: 1448:GCC uses the 1445: 1431: 1427: 1421: 1406: 1400: 1386: 1380: 1365: 1359: 1345: 1338: 1324: 1318: 1304: 1297: 1283: 1277: 1275: 1259: 1252: 1238: 1232: 1228: 1217: 1214: 1211: 1208: 1205: 1202: 1201: 1191: 1188: 1186: 1183: 1181: 1178: 1177: 1174: 1171: 1169: 1166: 1164: 1161: 1160: 1157: 1154: 1152: 1149: 1147: 1144: 1143: 1139: 1137: 1134: 1132: 1129: 1128: 1125: 1122: 1120: 1117: 1115: 1112: 1111: 1108: 1105: 1103: 1100: 1098: 1095: 1094: 1091: 1088: 1086: 1083: 1072: 1069: 1068: 1065: 1064:Public Domain 1062: 1060: 1057: 1055: 1052: 1051: 1048: 1045: 1043: 1040: 1038: 1035: 1034: 1031: 1030:Public Domain 1028: 1026: 1023: 1021: 1018: 1017: 1014: 1011: 1009: 1006: 1004: 1001: 1000: 997: 994: 992: 989: 987: 984: 983: 980: 977: 975: 972: 970: 967: 966: 962: 960: 957: 955: 952: 951: 947: 945: 942: 940: 937: 936: 932: 928: 925: 923: 920: 918: 914: 910: 907: 906: 903: 900: 898: 895: 893: 890: 889: 886: 883: 881: 877: 874: 872: 869: 868: 864: 861: 859:Library name 858: 857: 671: 668:-lgmpxx -lgmp 659: 652: 550:" %Zd 532:" %Zd 400:<gmp.h> 387: 379: 377: 372: 370: 366: 362: 358: 353: 351: 347: 342: 336: 332: 328: 325: 322: 318: 314: 311: 307: 306: 305: 303: 298: 296: 292: 287: 285: 284:GNU Classpath 281: 277: 273: 269: 265: 261: 257: 253: 249: 245: 241: 237: 233: 229: 225: 221: 217: 213: 209: 205: 202: 198: 194: 190: 186: 177: 171: 167: 164: 160: 156: 154: 150: 147: 144: 142: 138: 134: 130: 126: 123: 119: 115: 105: 103: 99: 95: 89: 83: 81: 77: 73: 59: 55: 52: 49: 47: 43: 39: 34: 27:Free software 19: 1887: 1876:Other topics 1862:Nagarjuna G. 1820:Contributors 1809: 1784:GNU LilyPond 1744:GNU Electric 1738: 1669:Build system 1459:. Retrieved 1457:. 2012-11-02 1444: 1433:. Retrieved 1420: 1409:. Retrieved 1399: 1388:. Retrieved 1379: 1368:. Retrieved 1366:. 2009-02-05 1358: 1347:. Retrieved 1337: 1326:. Retrieved 1317: 1306:. Retrieved 1296: 1285:. Retrieved 1261:. Retrieved 1251: 1240:. Retrieved 1231: 665: 653: 650: 385: 373: 354: 343: 340: 299: 291:cryptography 288: 195:library for 188: 184: 183: 46:Developer(s) 1714:GNU TeXmacs 1644:Linux-libre 1524:GNU Project 1047:Proprietary 1025:Common Lisp 361:Mathematica 135:optionally) 85:6.3.0  51:GNU Project 1915:Categories 1774:GNU Health 1719:GNU Octave 1461:2013-03-17 1435:2013-03-17 1411:2013-03-17 1390:2018-12-03 1370:2013-03-17 1349:2013-03-17 1328:2019-10-04 1308:2013-03-17 1287:2014-04-07 1242:2018-12-03 1223:References 1097:luajit-gmp 979:Apache 2.0 917:Math::GMPq 913:Math::GMPf 909:Math::GMPz 526:gmp_printf 331:processors 317:algorithms 315:Different 121:Written in 102:Repository 1842:Brian Fox 1794:GNU Chess 1724:GNU Taler 1709:GNU Emacs 1664:findutils 1659:coreutils 1430:Maplesoft 892:Math::GMP 862:Language 714:mpz_class 699:mpz_class 625:mpz_clear 613:mpz_clear 601:mpz_clear 568:"%Zd 1764:Gnuzilla 1679:binutils 1633:variants 1622:Software 1574:Licenses 1450:GNU MPFR 1204:GNU MPFR 1198:See also 865:License 822:<< 810:<< 798:<< 786:<< 780:<< 774:<< 762:<< 750:<< 744:<< 738:<< 681:#include 675:#include 490:mpz_init 397:#include 391:#include 382:Examples 371:(CGAL). 359:such as 352:(LGPL). 335:optimize 224:wrappers 204:integers 133:assembly 1810:more... 1694:GNUstep 1531:History 1263:30 July 1163:nim-gmp 1085:Haskell 1077:Integer 929:v1.0 + 765:"* 541:"* 502:mpz_mul 378:(GCC). 321:operand 191:) is a 169:Website 153:License 65: ( 1789:GNU Go 1779:GNUmed 1768:IceCat 1754:GNUnet 1548:Europe 1131:Zarith 1119:Delphi 1102:LuaJIT 1037:Ch GMP 944:Python 837:return 831:" 825:" 807:" 795:" 789:" 771:" 759:" 753:" 637:return 631:result 592:result 574:" 565:" 556:" 547:" 538:" 508:result 496:result 436:result 302:bignum 270:, and 260:Python 222:, but 216:memory 210:, and 201:signed 174:gmplib 159:LGPLv3 108:gmplib 1799:Gnash 1729:GNU R 1649:glibc 1553:India 1140:LGPL 1136:OCaml 948:LGPL 656:-lgmp 421:mpz_t 365:Maple 310:words 308:Full 276:Kaffe 248:OCaml 240:Julia 163:GPLv2 157:Dual 112:/repo 1804:Guix 1704:Jami 1699:GIMP 1689:GRUB 1654:Bash 1639:Hurd 1265:2023 1216:MPIR 1190:LGPL 1185:Java 1180:JGMP 1151:.NET 996:LGPL 991:Rust 974:Ruby 963:GPL 922:Perl 915:and 902:LGPL 897:Perl 885:LGPL 735:cout 690:main 412:void 406:main 363:and 278:, a 272:Rust 268:Ruby 252:Perl 244:.NET 193:free 176:.org 161:and 141:Type 110:.org 67:1991 60:1991 1739:GMP 1734:GSL 1684:GDB 1674:GCC 1629:GNU 1210:CLN 1173:MIT 1168:Nim 1156:MIT 1124:MIT 1107:MIT 1090:BSD 1013:PHP 1008:PHP 931:GPL 880:C++ 729:std 687:int 403:int 346:GNU 256:PHP 232:C++ 228:Ada 189:GMP 129:C++ 127:, ( 1917:: 1428:. 1273:^ 1042:Ch 911:, 878:, 828:\n 804:\n 792:\n 768:\n 756:\n 732::: 726:); 711:); 693:() 634:); 622:); 610:); 595:); 571:\n 562:\n 553:\n 544:\n 535:\n 523:); 499:); 487:); 484:10 463:); 460:10 297:. 286:. 266:, 262:, 258:, 254:, 250:, 246:, 242:, 238:, 236:C# 234:, 230:, 206:, 131:, 1770:) 1766:( 1635:) 1631:( 1516:e 1509:t 1502:v 1464:. 1438:. 1414:. 1393:. 1373:. 1352:. 1331:. 1311:. 1290:. 1267:. 1245:. 959:R 876:C 846:} 843:; 840:0 834:; 819:y 816:* 813:x 783:y 747:x 720:( 717:y 705:( 702:x 696:{ 646:} 643:; 640:0 628:( 619:y 616:( 607:x 604:( 589:, 586:y 583:, 580:x 577:, 529:( 520:y 517:, 514:x 511:, 505:( 493:( 481:, 475:, 472:y 469:( 457:, 451:, 448:x 445:( 439:; 433:, 430:y 427:, 424:x 418:{ 415:) 409:( 264:R 220:C 187:( 125:C 114:/ 69:) 20:)

Index

GNU Multi-Precision Library

Developer(s)
GNU Project
Stable release
Edit this on Wikidata
Repository
gmplib.org/repo/
C
C++
assembly
Type
Mathematical software
License
LGPLv3
GPLv2
gmplib.org
free
arbitrary-precision arithmetic
signed
integers
rational numbers
floating-point numbers
memory
C
wrappers
Ada
C++
C#
Julia

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.