package mlmpfr

  1. Overview
  2. Docs
OCaml C bindings for MPFR >= 4.2.0

Install

Dune Dependency

Authors

Maintainers

Sources

mlmpfr.4.2.0.tar.gz
sha256=1077a822f73daf69cc3f2aa921fafd0c3bc37425fed99179de6974f4f5307e8c
md5=c533de29431961d36f74c833f627f0c0

Description

The package provides bindings for the C MPFR library.

You need to have MPFR 4.2.0 or above installed on your system. See opam info mlmpfr for all available versions.

Published: 21 Dec 2023

README

README.md

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:

  • the mpfr_ prefix is ommited for all functions;

  • mpfr_init* and mpfr_set* functions are not provided in order to implement these bindings with respect to the functional paradigm (and immutability). Consequently, mpfr_clear* functions are not provided too, and so, the garbage collector is in charge of memory management. See initilization functions;

  • functions managing the following C types are not supported: unsigned long int, uintmax_t, intmax_t, float, long double, __float128, _Decimal64, _Decimal128, mpz_t, mpq_t, and mpf_t. Except for mpfr_sqrt_ui and mpfr_fac_ui which are partially supported in the range of the positive values of an OCaml signed integer. In fact, only the OCaml native types (signed 64-bit int, 64-bit float, and string) are supported. Thus, all functions named with *_[su]i* or *_d* are renamed here with *_int* or *_float*, respectively;

  • bindings to functions mpfr_*printf, mpfr_*random*, mpfr_get_patches, mpfr_buildopt_*, and, macros MPFR_VERSION*, mpfr_round_nearest_away are not implemented. Everything else has been ported!

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).

  • From sources (github repo or with latest releases): in mlmpfr main directory, on branch master or release_411. Make sure that you have the proper MPFR library version installed on your system because mlmpfr won't check for it (see utils/mpfr_version.c).

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).

  • From opam, targeting latest release (see opam info to list available releases):

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.

Dependencies (4)

  1. conf-mpfr
  2. dune-configurator
  3. dune >= "2.9"
  4. ocaml >= "4.04"

Dev Dependencies (1)

  1. odoc with-doc

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.