Crate gmp_mpfr_sys [−] [src]
Rust low-level bindings for GMP, MPFR and MPC
The gmp-mpfr-sys
crate provides Rust low-level bindings for
- the GNU Multiple Precision Arithmetic Library (GMP),
- the GNU MPFR Library, a library for multiple-precision floating-point computations, and
- GNU MPC, a library for the arithmetic of complex numbers with arbitrarily high precision.
This crate is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
See the LGPL and GPL for details.
Modules
This crate provides a low-level interface to GMP, MPFR and MPC in three modules. The documentation of the three modules contains links for each function, constant and type into the respective documentation of GMP, MPFR and MPC. The three modules of this crate are:
gmp
provides external FFI bindings to GMP.mpfr
provides external FFI bindings to MPFR.mpc
provides external FFI bindings to MPC.
If you want a high-level API, consider using the following crates:
rugint
provides arbitrary-precision integers based on GMP.rugrat
provides arbitrary-precision rational number based on GMP.rugflo
provides arbitrary-precision floating-point numbers based on MPFR.rugcom
provides arbitrary-precision complex numbers based on MPC.
Notes
Name prefixes
Since modules and enumerated types provide namespacing, most
prefixes in the C names are removed. However, when the prefix is
not a whole word it is not removed, for example
mp_set_memory_functions()
becomes gmp::set_memory_functions()
,
but mpz_init()
becomes gmp::mpz_init()
not gmp::z_init()
,
and MPFR_RNDN
in enum MPFR_RND_T
becomes mpfr::rnd_t::RNDN
not mpfr::rnd_t::N
. Also, the types mpfr::mpfr_t
and
mpc::mpc_t
are not shortened to mpfr::t
or mpc::t
.
Types
Unlike in the C libraries, the types gmp::mpz_t
, gmp::mpq_t
,
gmp::mpf_t
, gmp::rand_state_t
, mpfr::mpfr_t
and mpc::mpc_t
are defined directly as structs, not as single-element arrays.
Undocumented or obsolete functions
The bindings do not cover undocumented or obsolete functions and macros.
Usage
To use gmp-mpfr-sys
in your crate, add
extern crate gmp_mpfr_sys;
to the crate root and add
gmp-mpfr-sys
as a dependency in Cargo.toml
:
[dependencies]
gmp-mpfr-sys = "0.5.2"
Building on GNU/Linux
To build on GNU/Linux, simply make sure you have diffutils
, gcc
and make
installed on your system. For example on Fedora:
sudo dnf install diffutils gcc make
Building on macOS
To build on macOS, you need the command-line developer tools. An
easy way to install them is to start building the crate using
cargo build
. If the tools are not installed yet, a popup should
appear which should help you install them.
Building on Windows
You can build on Windows with the Rust GNU toolchain and an up-to-date MSYS2 installation. Some steps for a 64-bit environment are listed below. (32-bit: Changes for a 32-bit environment are written in brackets like this comment.)
Install MSYS2 using the installer.
Launch the MSYS2 MinGW 64-bit terminal from the start menu. (32-bit: Launch the MSYS2 MinGW 32-bit terminal instead.)
Install the required tools.
pacman -S pacman-mirrors pacman -S diffutils make mingw-w64-x86_64-gcc
(32-bit: Install
mingw-w64-i686-gcc
instead ofmingw-w64-x86_64-gcc
.)
Then, to build a crate with a dependency on this crate:
Launch the MSYS MinGW 64-bit terminal from the start menu. (32-bit: Launch the MSYS2 MinGW 32-bit terminal instead.)
Change to the crate directory.
Note that building the GMP and MPFR libraries in MSYS with absolute paths does not work very well, so relative paths are used. If your crate is inside
C:\msys64
and the.cargo
directory is outsideC:\msys64
, this will not work. Please move your crate to the same side ofC:\msys64
as.cargo
.Build the crate using
cargo
.
Modules
gmp | |
mpc | |
mpfr |