Module gmp_mpfr_sys::mpfr[][src]

Expand description

Function and type bindings for the MPFR library.

Examples

use core::mem::MaybeUninit;
use gmp_mpfr_sys::mpfr;
let one_third = 1.0_f64 / 3.0;
unsafe {
    let mut f = MaybeUninit::uninit();
    mpfr::init2(f.as_mut_ptr(), 53);
    let mut f = f.assume_init();
    let dir = mpfr::set_d(&mut f, one_third, mpfr::rnd_t::RNDN);
    assert_eq!(dir, 0);
    let d = mpfr::get_d(&f, mpfr::rnd_t::RNDN);
    assert_eq!(d, one_third);
    mpfr::clear(&mut f);
}

The following example is a translation of the MPFR sample found on the MPFR website. The program computes a lower bound on 1 + 1/1! + 1/2! + … + 1/100! using 200-bit precision. The program outputs:

Sum is 2.7182818284590452353602874713526624977572470936999595749669131e0

use core::mem::MaybeUninit;
use gmp_mpfr_sys::mpfr::{self, rnd_t};
use libc::{self, c_char, c_int, STDOUT_FILENO};

fn main() {
    unsafe {
        let mut t = MaybeUninit::uninit();
        mpfr::init2(t.as_mut_ptr(), 200);
        let mut t = t.assume_init();
        mpfr::set_d(&mut t, 1.0, rnd_t::RNDD);

        let mut s = MaybeUninit::uninit();
        mpfr::init2(s.as_mut_ptr(), 200);
        let mut s = s.assume_init();
        mpfr::set_d(&mut s, 1.0, rnd_t::RNDD);

        let mut u = MaybeUninit::uninit();
        mpfr::init2(u.as_mut_ptr(), 200);
        let mut u = u.assume_init();

        for i in 1..=100 {
            mpfr::mul_ui(&mut t, &t, i, rnd_t::RNDU);
            mpfr::set_d(&mut u, 1.0, rnd_t::RNDD);
            mpfr::div(&mut u, &u, &t, rnd_t::RNDD);
            mpfr::add(&mut s, &s, &u, rnd_t::RNDD);
        }

        let stdout = libc::fdopen(STDOUT_FILENO, b"w\0".as_ptr() as *const c_char);
        libc::fputs(b"Sum is \0".as_ptr() as *const c_char, stdout);
        mpfr::out_str(stdout, 10, 0, &s, rnd_t::RNDD);
        libc::fputc(b'\n' as c_int, stdout);
        libc::fclose(stdout);

        mpfr::clear(&mut s);
        mpfr::clear(&mut t);
        mpfr::clear(&mut u);
        mpfr::free_cache();
    }
}

Structs

Enums

Constants

Functions

See: mpfr_abs

See: mpfr_acos

See: mpfr_add

See: mpfr_agm

See: mpfr_ai

See: mpfr_asin

See: mpfr_atan

See: mpfr_beta

See: mpfr_cbrt

See: mpfr_ceil

See: mpfr_cmp

See: mpfr_cos

See: mpfr_cosh

See: mpfr_cot

See: mpfr_coth

See: mpfr_csc

See: mpfr_csch

See: mpfr_dim

See: mpfr_div

See: mpfr_dot

See: mpfr_dump

See: mpfr_eint

See: mpfr_eq

See: mpfr_erf

See: mpfr_erfc

See: mpfr_exp

See: mpfr_exp2

See: mpfr_fma

See: mpfr_fmma

See: mpfr_fmms

See: mpfr_fmod

See: mpfr_fms

See: mpfr_frac

grandomDeprecated

See: mpfr_init

See: mpfr_j0

See: mpfr_j1

See: mpfr_jn

See: mpfr_li2

See: mpfr_log

See: mpfr_log2

See: mpfr_max

See: mpfr_min

See: mpfr_modf

See: mpfr_mul

See: mpfr_neg

See: mpfr_pow

See: mpfr_rint

rootDeprecated

See: mpfr_root

See: mpfr_sec

See: mpfr_sech

See: mpfr_set

See: mpfr_sgn

See: mpfr_sin

See: mpfr_sinh

See: mpfr_sqr

See: mpfr_sub

See: mpfr_sum

See: mpfr_swap

See: mpfr_tan

See: mpfr_tanh

See: mpfr_y0

See: mpfr_y1

See: mpfr_yn

See: mpfr_zeta

Type Definitions