Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Bignum module for Ocaml?

Tags:

ocaml

I've done some searching around and apparently there used to be a Bignum module in the standard library according to this But at this point I don't see anything in the standard library.

like image 912
aneccodeal Avatar asked Oct 06 '11 21:10

aneccodeal


2 Answers

There is no bignum module in the core OCaml distribution. The official recommendation is to use the third-party Zarith library, specifically its Z module.

If you've installed OCaml as part of your operating system distribution, see if it has a package for Zarith. For example, on Debian, Ubuntu and derivatives, it's libzarith-ocaml-dev. If Zarith isn't available through your operating system, install it with OPAM:

opam install zarith

When building your application, compile with one of

ocamlc -I +zarith zarith.cma …
ocamlopt -I +zarith zarith.cmxa …
ocamlfind <COMMAND> -package zarith -linkpkg …

To use Zarith in the toplevel:

ocaml -I +zarith zarith.cma zarith_top.cma

Older versions of Ocaml had a bignum module in the standard distribution (but not in the standard library: it didn't require separate installation, but had to be linked explicitly). It was the nums library, and its main module Num. Since OCaml 4.06, the nums library is distributed separately.

Technically, there is no bignum module in the standard library, because the standard library in Ocaml terminology is the default library that programs are compiled against, and there's no bignum module in that. Nor is there a Bignum library — because the bignum library is called nums, and its main module is called Num. It has been part of the standard Ocaml distribution since before Ocaml was called Ocaml, and still is.

like image 75
Gilles 'SO- stop being evil' Avatar answered Nov 13 '22 21:11

Gilles 'SO- stop being evil'


You are looking for the num library. Technically this is not part of the "Standard Library", but is part of the standard distribution. Thus, simply compile with this library, and it will be available. Also, you might be interested in the new zarith library. I am unsure how the two compare.

like image 9
Ashish Agarwal Avatar answered Nov 13 '22 21:11

Ashish Agarwal