Crate gmp_mpfr_sys [−] [src]
gmp-mpfr-sys crate provides Rust FFI bindings for:
- the GNU Multiple Precision Arithmetic Library (GMP) version 6.1.2, a library for arbitrary precision arithmetic,
- the GNU MPFR Library version 4.0.0, a library for multiple-precision floating-point computations with correct rounding, and
- GNU MPC version 1.1.0, a library for the arithmetic of complex numbers with arbitrarily high precision and correct rounding.
The source of the three libraries is included in the package.
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 full text of the GNU LGPL and GNU GPL for details.
This crate required rustc version 1.13.0.
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 libraries. The three modules of this crate are:
gmpprovides external FFI bindings to GMP.
mpfrprovides external FFI bindings to MPFR.
mpcprovides external FFI bindings to MPC.
If you want a high-level API, consider using the
which provides big integer and floating-point numbers. Its main
- big integers with arbitrary precision based on GMP,
- big rational numbers with arbitrary precision based on GMP,
- multi-precision floating-point numbers with correct rounding based on MPFR, and
- multi-precision complex numbers with correct rounding based on MPC.
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
enum MPFR_RND_T becomes
mpfr::rnd_t::N. Also, the types
mpc::mpc_t are not shortened to
Unlike in the C libraries, the types
are defined directly as structs, not as single-element arrays.
The bindings do not cover undocumented or obsolete functions and macros.
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
[dependencies] gmp-mpfr-sys = "1.1.0"
gmp-mpfr-sys crate has two optional features
mpc to include the MPFR and MPC libraries respectively. The GMP
library is always included. The optional features are enabled by
default; to disable them add this to
[dependencies.gmp-mpfr-sys] version = "1.1.0" default-features = false
To use features selectively, you can add this to
[dependencies.gmp-mpfr-sys] version = "1.1.0" default-features = false # Pick which features to use features = ["mpfr"]
Note that the the
mpc feature depends on, and will enable, the
To build on GNU/Linux, simply make sure you have
m4 installed on your system. For example on
sudo dnf install diffutils gcc make m4
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.
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.)
To install MSYS2:
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
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, MPFR and MPC libraries in MSYS with absolute paths does not work very well, so relative paths are used. If your crate is inside
.cargodirectory is outside
C:\msys64, this will not work. Please move your crate to the same side of
Build the crate using
Function and type bindings for the GMP library.
Function and type bindings for the MPC library.
Function and type bindings for the MPFR library.