Module gmp_mpfr_sys::mpfr[][src]

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

mpfr_t

See: mpfr_t and Internals

Enums

rnd_t

See: mpfr_rnd_t

Constants

FREE_GLOBAL_CACHE

See: mpfr_free_cache2

FREE_LOCAL_CACHE

See: mpfr_free_cache2

INF_KIND

See: mpfr_custom_init_set

NAN_KIND

See: mpfr_custom_init_set

PREC_MAX

See: Nomenclature and Types

PREC_MIN

See: Nomenclature and Types

REGULAR_KIND

See: mpfr_custom_init_set

VERSION

See: MPFR_VERSION

VERSION_MAJOR

See: MPFR_VERSION_MAJOR

VERSION_MINOR

See: MPFR_VERSION_MINOR

VERSION_PATCHLEVEL

See: MPFR_VERSION_PATCHLEVEL

VERSION_STRING

See: MPFR_VERSION_STRING

ZERO_KIND

See: mpfr_custom_init_set

Functions

VERSION_NUM

See: MPFR_VERSION_NUM

abs

See: mpfr_abs

acos

See: mpfr_acos

acosh

See: mpfr_acosh

add

See: mpfr_add

add_d

See: mpfr_add_d

add_q

See: mpfr_add_q

add_si

See: mpfr_add_si

add_ui

See: mpfr_add_ui

add_z

See: mpfr_add_z

agm

See: mpfr_agm

ai

See: mpfr_ai

asin

See: mpfr_asin

asinh

See: mpfr_asinh

asprintf

See: mpfr_asprintf

atan

See: mpfr_atan

atan2

See: mpfr_atan2

atanh

See: mpfr_atanh

beta

See: mpfr_beta

buildopt_decimal_p

See: mpfr_buildopt_decimal_p

buildopt_float128_p

See: mpfr_buildopt_float128_p

buildopt_gmpinternals_p

See: mpfr_buildopt_gmpinternals_p

buildopt_sharedcache_p

See: mpfr_buildopt_sharedcache_p

buildopt_tls_p

See: mpfr_buildopt_tls_p

buildopt_tune_case

See: mpfr_buildopt_tune_case

can_round

See: mpfr_can_round

cbrt

See: mpfr_cbrt

ceil

See: mpfr_ceil

check_range

See: mpfr_check_range

clear

See: mpfr_clear

clear_divby0

See: mpfr_clear_divby0

clear_erangeflag

See: mpfr_clear_erangeflag

clear_flags

See: mpfr_clear_flags

clear_inexflag

See: mpfr_clear_inexflag

clear_nanflag

See: mpfr_clear_nanflag

clear_overflow

See: mpfr_clear_overflow

clear_underflow

See: mpfr_clear_underflow

clears

See: mpfr_clears

cmp

See: mpfr_cmp

cmp_d

See: mpfr_cmp_d

cmp_f

See: mpfr_cmp_f

cmp_q

See: mpfr_cmp_q

cmp_si

See: mpfr_cmp_si

cmp_si_2exp

See: mpfr_cmp_si_2exp

cmp_ui

See: mpfr_cmp_ui

cmp_ui_2exp

See: mpfr_cmp_ui_2exp

cmp_z

See: mpfr_cmp_z

cmpabs

See: mpfr_cmpabs

cmpabs_ui

See: mpfr_cmpabs_ui

const_catalan

See: mpfr_const_catalan

const_euler

See: mpfr_const_euler

const_log2

See: mpfr_const_log2

const_pi

See: mpfr_const_pi

copysign

See: mpfr_copysign

cos

See: mpfr_cos

cosh

See: mpfr_cosh

cot

See: mpfr_cot

coth

See: mpfr_coth

csc

See: mpfr_csc

csch

See: mpfr_csch

custom_get_exp

See: mpfr_custom_get_exp

custom_get_kind

See: mpfr_custom_get_kind

custom_get_significand

See: mpfr_custom_get_significand

custom_get_size

See: mpfr_custom_get_size

custom_init

See: mpfr_custom_init

custom_init_set

See: mpfr_custom_init_set

custom_move

See: mpfr_custom_move

d_div

See: mpfr_d_div

d_sub

See: mpfr_d_sub

digamma

See: mpfr_digamma

dim

See: mpfr_dim

div

See: mpfr_div

div_2exp

See: mpfr_div_2exp

div_2si

See: mpfr_div_2si

div_2ui

See: mpfr_div_2ui

div_d

See: mpfr_div_d

div_q

See: mpfr_div_q

div_si

See: mpfr_div_si

div_ui

See: mpfr_div_ui

div_z

See: mpfr_div_z

divby0_p

See: mpfr_divby0_p

dot

See: mpfr_dot

dump

See: mpfr_dump

eint

See: mpfr_eint

eq

See: mpfr_eq

equal_p

See: mpfr_equal_p

erandom

See: mpfr_erandom

erangeflag_p

See: mpfr_erangeflag_p

erf

See: mpfr_erf

erfc

See: mpfr_erfc

exp

See: mpfr_exp

exp2

See: mpfr_exp2

exp10

See: mpfr_exp10

expm1

See: mpfr_expm1

fac_ui

See: mpfr_fac_ui

fits_intmax_p

See: mpfr_fits_intmax_p

fits_sint_p

See: mpfr_fits_sint_p

fits_slong_p

See: mpfr_fits_slong_p

fits_sshort_p

See: mpfr_fits_sshort_p

fits_uint_p

See: mpfr_fits_uint_p

fits_uintmax_p

See: mpfr_fits_uintmax_p

fits_ulong_p

See: mpfr_fits_ulong_p

fits_ushort_p

See: mpfr_fits_ushort_p

flags_clear

See: mpfr_flags_clear

flags_restore

See: mpfr_flags_restore

flags_save

See: mpfr_flags_save

flags_set

See: mpfr_flags_set

flags_test

See: mpfr_flags_test

floor

See: mpfr_floor

fma

See: mpfr_fma

fmma

See: mpfr_fmma

fmms

See: mpfr_fmms

fmod

See: mpfr_fmod

fmodquo

See: mpfr_fmodquo

fms

See: mpfr_fms

fpif_export

See: mpfr_fpif_export

fpif_import

See: mpfr_fpif_import

fprintf

See: mpfr_fprintf

frac

See: mpfr_frac

free_cache

See: mpfr_free_cache

free_cache2

See: mpfr_free_cache2

free_pool

See: mpfr_free_pool

free_str

See: mpfr_free_str

frexp

See: mpfr_frexp

gamma

See: mpfr_gamma

gamma_inc

See: mpfr_gamma_inc

get_d

See: mpfr_get_d

get_d_2exp

See: mpfr_get_d_2exp

get_default_prec

See: mpfr_get_default_prec

get_default_rounding_mode

See: mpfr_get_default_rounding_mode

get_emax

See: mpfr_get_emax

get_emax_max

See: mpfr_get_emax_max

get_emax_min

See: mpfr_get_emax_min

get_emin

See: mpfr_get_emin

get_emin_max

See: mpfr_get_emin_max

get_emin_min

See: mpfr_get_emin_min

get_exp

See: mpfr_get_exp

get_f

See: mpfr_get_f

get_flt

See: mpfr_get_flt

get_patches

See: mpfr_get_patches

get_prec

See: mpfr_get_prec

get_q

See: mpfr_get_q

get_si

See: mpfr_get_si

get_sj

See: mpfr_get_sj

get_str

See: mpfr_get_str

get_str_ndigits

See: mpfr_get_str_ndigits

get_ui

See: mpfr_get_ui

get_uj

See: mpfr_get_uj

get_version

See: mpfr_get_version

get_z

See: mpfr_get_z

get_z_2exp

See: mpfr_get_z_2exp

grandomDeprecated

See: mpfr_grandom

greater_p

See: mpfr_greater_p

greaterequal_p

See: mpfr_greaterequal_p

hypot

See: mpfr_hypot

inexflag_p

See: mpfr_inexflag_p

inf_p

See: mpfr_inf_p

init

See: mpfr_init

init2

See: mpfr_init2

init_set

See: mpfr_init_set

init_set_d

See: mpfr_init_set_d

init_set_f

See: mpfr_init_set_f

init_set_q

See: mpfr_init_set_q

init_set_si

See: mpfr_init_set_si

init_set_str

See: mpfr_init_set_str

init_set_ui

See: mpfr_init_set_ui

init_set_z

See: mpfr_init_set_z

inits

See: mpfr_inits

inits2

See: mpfr_inits2

inp_str

See: mpfr_inp_str

integer_p

See: mpfr_integer_p

j0

See: mpfr_j0

j1

See: mpfr_j1

jn

See: mpfr_jn

less_p

See: mpfr_less_p

lessequal_p

See: mpfr_lessequal_p

lessgreater_p

See: mpfr_lessgreater_p

lgamma

See: mpfr_lgamma

li2

See: mpfr_li2

lngamma

See: mpfr_lngamma

log

See: mpfr_log

log1p

See: mpfr_log1p

log2

See: mpfr_log2

log10

See: mpfr_log10

log_ui

See: mpfr_log_ui

max

See: mpfr_max

min

See: mpfr_min

min_prec

See: mpfr_min_prec

modf

See: mpfr_modf

mp_memory_cleanup

See: mpfr_mp_memory_cleanup

mul

See: mpfr_mul

mul_2exp

See: mpfr_mul_2exp

mul_2si

See: mpfr_mul_2si

mul_2ui

See: mpfr_mul_2ui

mul_d

See: mpfr_mul_d

mul_q

See: mpfr_mul_q

mul_si

See: mpfr_mul_si

mul_ui

See: mpfr_mul_ui

mul_z

See: mpfr_mul_z

nan_p

See: mpfr_nan_p

nanflag_p

See: mpfr_nanflag_p

neg

See: mpfr_neg

nextabove

See: mpfr_nextabove

nextbelow

See: mpfr_nextbelow

nexttoward

See: mpfr_nexttoward

nrandom

See: mpfr_nrandom

number_p

See: mpfr_number_p

out_str

See: mpfr_out_str

overflow_p

See: mpfr_overflow_p

pow

See: mpfr_pow

pow_si

See: mpfr_pow_si

pow_ui

See: mpfr_pow_ui

pow_z

See: mpfr_pow_z

prec_round

See: mpfr_prec_round

print_rnd_mode

See: mpfr_print_rnd_mode

printf

See: mpfr_printf

rec_sqrt

See: mpfr_rec_sqrt

regular_p

See: mpfr_regular_p

reldiff

See: mpfr_reldiff

remainder

See: mpfr_remainder

remquo

See: mpfr_remquo

rint

See: mpfr_rint

rint_ceil

See: mpfr_rint_ceil

rint_floor

See: mpfr_rint_floor

rint_round

See: mpfr_rint_round

rint_roundeven

See: mpfr_rint_roundeven

rint_trunc

See: mpfr_rint_trunc

rootDeprecated

See: mpfr_root

rootn_ui

See: mpfr_rootn_ui

round

See: mpfr_round

roundeven

See: mpfr_roundeven

sec

See: mpfr_sec

sech

See: mpfr_sech

set

See: mpfr_set

set_d

See: mpfr_set_d

set_default_prec

See: mpfr_set_default_prec

set_default_rounding_mode

See: mpfr_set_default_rounding_mode

set_divby0

See: mpfr_set_divby0

set_emax

See: mpfr_set_emax

set_emin

See: mpfr_set_emin

set_erangeflag

See: mpfr_set_erangeflag

set_exp

See: mpfr_set_exp

set_f

See: mpfr_set_f

set_flt

See: mpfr_set_flt

set_inexflag

See: mpfr_set_inexflag

set_inf

See: mpfr_set_inf

set_nan

See: mpfr_set_nan

set_nanflag

See: mpfr_set_nanflag

set_overflow

See: mpfr_set_overflow

set_prec

See: mpfr_set_prec

set_prec_raw

See: mpfr_set_prec_raw

set_q

See: mpfr_set_q

set_si

See: mpfr_set_si

set_si_2exp

See: mpfr_set_si_2exp

set_sj

See: mpfr_set_sj

set_sj_2exp

See: mpfr_set_sj_2exp

set_str

See: mpfr_set_str

set_ui

See: mpfr_set_ui

set_ui_2exp

See: mpfr_set_ui_2exp

set_uj

See: mpfr_set_uj

set_uj_2exp

See: mpfr_set_uj_2exp

set_underflow

See: mpfr_set_underflow

set_z

See: mpfr_set_z

set_z_2exp

See: mpfr_set_z_2exp

set_zero

See: mpfr_set_zero

setsign

See: mpfr_setsign

sgn

See: mpfr_sgn

si_div

See: mpfr_si_div

si_sub

See: mpfr_si_sub

signbit

See: mpfr_signbit

sin

See: mpfr_sin

sin_cos

See: mpfr_sin_cos

sinh

See: mpfr_sinh

sinh_cosh

See: mpfr_sinh_cosh

snprintf

See: mpfr_snprintf

sprintf

See: mpfr_sprintf

sqr

See: mpfr_sqr

sqrt

See: mpfr_rec_sqrt

sqrt_ui

See: mpfr_sqrt_ui

strtofr

See: mpfr_strtofr

sub

See: mpfr_sub

sub_d

See: mpfr_sub_d

sub_q

See: mpfr_sub_q

sub_si

See: mpfr_sub_si

sub_ui

See: mpfr_sub_ui

sub_z

See: mpfr_sub_z

subnormalize

See: mpfr_subnormalize

sum

See: mpfr_sum

swap

See: mpfr_swap

tan

See: mpfr_tan

tanh

See: mpfr_tanh

total_order_p

See: mpfr_total_order_p

trunc

See: mpfr_trunc

ui_div

See: mpfr_ui_div

ui_pow

See: mpfr_ui_pow

ui_pow_ui

See: mpfr_ui_pow_ui

ui_sub

See: mpfr_ui_sub

underflow_p

See: mpfr_underflow_p

unordered_p

See: mpfr_unordered_p

urandom

See: mpfr_urandom

urandomb

See: mpfr_urandomb

y0

See: mpfr_y0

y1

See: mpfr_y1

yn

See: mpfr_yn

z_sub

See: mpfr_z_sub

zero_p

See: mpfr_zero_p

zeta

See: mpfr_zeta

zeta_ui

See: mpfr_zeta_ui

Type Definitions

exp_t

See: Exception Related Functions

flags_t

See: mpfr_flags_t

prec_t

See: mpfr_prec_t