master

mlmpfr

OCaml bindings for MPFR.

mlmpfr provides mpfr_float, an immutable data structure that contains a mpfr_t number, as well as an optional ternary value, as provided by (and described in) the MPFR library.

A few distinctions are made from the original C library:

build and install

Building mlmpfr.4.1.1 depends on dune (an OCaml build system), ocaml version >= 4.04, and MPFR library version 4.1.1 (see footnote for building older mlmpfr releases). Basically you just need to install mlmpfr via the opam package manager, which will triggers all the dependencies (such as dune for example).

dune build @install @runtest
dune install

Use --prefix <path> to set another path (the default path is the parent of the directory where ocamlc was found).

opam install mlmpfr
# `opam remove mlmpfr` to remove the package.

documentation

Documentation depends on package odoc.

dune build @doc

then, see _build/default/_doc/_html/index.html. An online version is available here.

usage

For example, let example.ml as follows:

module M = Mlmpfr

let _ =
  let op = M.make_from_float (~-. 1. /. 3.) in
  Printf.printf "%s\n" (M.get_formatted_str (M.cos op))

Compile the above code with:

$ ocamlfind ocamlc -package mlmpfr -linkpkg example.ml -o a.out

will result in:

$ ./a.out
9.449569463147377e-01

You can also use dune with

$ dune exec examples/example.exe
9.449569463147377e-01

Note: install an older release of mlmpfr

Older releases of mlmpfr (3.1.6, 4.0.0, and 4.0.1) depend on oasis, an obsolete build system replaced by dune since mlmpfr.4.0.2. Use opam if you need to install an older release of mlmpfr, as for example:

opam install mlmpfr.3.1.6

Or, you can build it from the sources, as for example from branch release_316:

oasis setup
./configure --enable-tests
make
make test
make install
# `make uninstall` to remove mlmpfr library.

opam packages mlmpfr.4.0.0 and mlmpfr.4.0.1 also exist and are suitable for MPFR 4.0.0 and 4.0.1 versions.

Note: build examples with an older release of mlmpfr

You'll need to link with -cclib -lmpfr (along with ocamlopt) if you are using released versions of mlmpfr (as the ones provided by opam), since mlmpfr wasn't linked with mpfr by default before.