I'm in need of a bignum library for representing large integers. What options do I have with the D programming language? Are there, for instance, GMP bindings?
Update:
I'm trying to use the inbuilt BigInt as described below but it appears it's not available with the GDC.
import std.bigint;
import std.stdio;
void main()
{
BigInt n = "123";
writefln(n);
}
When I try to compile this code with gdc main.d
I'm told it can't find bigint.d. Does gdc only implement some of the library or am I doing something wrong?
GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. There is no practical limit to the precision except the ones implied by the available memory in the machine GMP runs on.
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.
The MPFR library is a C library for multiple-precision floating-point computations with correct rounding.
Generally, In languages like C/C++, the precision of integers is limited to 64-bit, but Python has built-in support for Arbitrary-precision integers.
If what you're looking for is a big integer type, then there's BigInt
in the standard library. On the other hand, if you're specifically looking to use GMP, then all you have to do is have extern(C)
declarations for the appropriate types and functions in GMP that you need, and you can call them directly from D. Check out out this page for more details on how to use C code in D.
Paul Anderson is working on a BigFloat abstraction for the standard library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With