Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What bignum libraries work with D?

Tags:

d

biginteger

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?

like image 563
daenthusiast Avatar asked Sep 18 '11 02:09

daenthusiast


People also ask

What is GMP library used for?

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.

How does arbitrary-precision arithmetic work?

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.

What is Libmpfr?

The MPFR library is a C library for multiple-precision floating-point computations with correct rounding.

Does Python have arbitrary-precision?

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.


2 Answers

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.

like image 89
Jonathan M Davis Avatar answered Oct 19 '22 00:10

Jonathan M Davis


Paul Anderson is working on a BigFloat abstraction for the standard library.

like image 4
Andrei Alexandrescu Avatar answered Oct 18 '22 23:10

Andrei Alexandrescu