Module gmp_mpfr_sys::mpfr
source · 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 = {
let mut f = MaybeUninit::uninit();
mpfr::init2(f.as_mut_ptr(), 53);
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::ffi::c_int;
use core::mem::MaybeUninit;
use gmp_mpfr_sys::mpfr;
use gmp_mpfr_sys::mpfr::rnd_t;
use libc::STDOUT_FILENO;
fn main() {
unsafe {
let mut t = {
let mut t = MaybeUninit::uninit();
mpfr::init2(t.as_mut_ptr(), 200);
t.assume_init()
};
mpfr::set_d(&mut t, 1.0, rnd_t::RNDD);
let mut s = {
let mut s = MaybeUninit::uninit();
mpfr::init2(s.as_mut_ptr(), 200);
s.assume_init()
};
mpfr::set_d(&mut s, 1.0, rnd_t::RNDD);
let mut u = {
let mut u = MaybeUninit::uninit();
mpfr::init2(u.as_mut_ptr(), 200);
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().cast());
libc::fputs(b"Sum is \0".as_ptr().cast(), 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§
- See:
mpfr_rnd_t
Constants§
- See:
mpfr_free_cache2
- See:
mpfr_free_cache2
- See:
mpfr_custom_init_set
- See:
mpfr_custom_init_set
- See:
mpfr_custom_init_set
- See:
MPFR_VERSION
- See:
MPFR_VERSION_MAJOR
- See:
MPFR_VERSION_MINOR
- See:
MPFR_VERSION_STRING
- See:
mpfr_custom_init_set
Functions§
- See:
MPFR_VERSION_NUM
- abs⚠See:
mpfr_abs
- acos⚠See:
mpfr_acos
- See:
mpfr_acosh
- See:
mpfr_acospi
- See:
mpfr_acosu
- add⚠See:
mpfr_add
- See:
mpfr_add_d
- See:
mpfr_add_q
- See:
mpfr_add_si
- See:
mpfr_add_ui
- See:
mpfr_add_z
- agm⚠See:
mpfr_agm
- ai⚠See:
mpfr_ai
- asin⚠See:
mpfr_asin
- See:
mpfr_asinh
- See:
mpfr_asinpi
- See:
mpfr_asinu
- See:
mpfr_asprintf
- atan⚠See:
mpfr_atan
- See:
mpfr_atan2
- See:
mpfr_atan2pi
- See:
mpfr_atan2u
- See:
mpfr_atanh
- See:
mpfr_atanpi
- See:
mpfr_atanu
- beta⚠See:
mpfr_beta
- See:
mpfr_buildopt_tls_p
- See:
mpfr_can_round
- cbrt⚠See:
mpfr_cbrt
- ceil⚠See:
mpfr_ceil
- See:
mpfr_check_range
- See:
mpfr_clear
- See:
mpfr_clear_divby0
- See:
mpfr_clear_flags
- See:
mpfr_clear_inexflag
- See:
mpfr_clear_nanflag
- See:
mpfr_clear_overflow
- See:
mpfr_clear_underflow
- See:
mpfr_clears
- cmp⚠See:
mpfr_cmp
- See:
mpfr_cmp_d
- See:
mpfr_cmp_f
- See:
mpfr_cmp_q
- See:
mpfr_cmp_si
- See:
mpfr_cmp_si_2exp
- See:
mpfr_cmp_ui
- See:
mpfr_cmp_ui_2exp
- See:
mpfr_cmp_z
- See:
mpfr_cmpabs
- See:
mpfr_cmpabs_ui
- See:
mpfr_compound_si
- See:
mpfr_const_catalan
- See:
mpfr_const_euler
- See:
mpfr_const_log2
- See:
mpfr_const_pi
- See:
mpfr_copysign
- cos⚠See:
mpfr_cos
- cosh⚠See:
mpfr_cosh
- See:
mpfr_cospi
- cosu⚠See:
mpfr_cosu
- cot⚠See:
mpfr_cot
- coth⚠See:
mpfr_coth
- csc⚠See:
mpfr_csc
- csch⚠See:
mpfr_csch
- See:
mpfr_custom_get_exp
- See:
mpfr_custom_get_kind
- See:
mpfr_custom_get_size
- See:
mpfr_custom_init
- See:
mpfr_custom_init_set
- See:
mpfr_custom_move
- See:
mpfr_d_div
- See:
mpfr_d_sub
- See:
mpfr_digamma
- dim⚠See:
mpfr_dim
- div⚠See:
mpfr_div
- See:
mpfr_div_2exp
- See:
mpfr_div_2si
- See:
mpfr_div_2ui
- See:
mpfr_div_d
- See:
mpfr_div_q
- See:
mpfr_div_si
- See:
mpfr_div_ui
- See:
mpfr_div_z
- See:
mpfr_divby0_p
- dot⚠See:
mpfr_dot
- dump⚠See:
mpfr_dump
- eint⚠See:
mpfr_eint
- eq⚠See:
mpfr_eq
- See:
mpfr_equal_p
- See:
mpfr_erandom
- See:
mpfr_erangeflag_p
- erf⚠See:
mpfr_erf
- erfc⚠See:
mpfr_erfc
- exp⚠See:
mpfr_exp
- exp2⚠See:
mpfr_exp2
- See:
mpfr_exp2m1
- See:
mpfr_exp10
- See:
mpfr_exp10m1
- See:
mpfr_expm1
- See:
mpfr_fac_ui
- See:
mpfr_fits_intmax_p
- See:
mpfr_fits_sint_p
- See:
mpfr_fits_slong_p
- See:
mpfr_fits_sshort_p
- See:
mpfr_fits_uint_p
- See:
mpfr_fits_uintmax_p
- See:
mpfr_fits_ulong_p
- See:
mpfr_fits_ushort_p
- See:
mpfr_flags_clear
- See:
mpfr_flags_restore
- See:
mpfr_flags_save
- See:
mpfr_flags_set
- See:
mpfr_flags_test
- See:
mpfr_floor
- fma⚠See:
mpfr_fma
- fmma⚠See:
mpfr_fmma
- fmms⚠See:
mpfr_fmms
- fmod⚠See:
mpfr_fmod
- See:
mpfr_fmod_ui
- See:
mpfr_fmodquo
- fms⚠See:
mpfr_fms
- See:
mpfr_fpif_export
- See:
mpfr_fpif_import
- See:
mpfr_fprintf
- frac⚠See:
mpfr_frac
- See:
mpfr_free_cache
- See:
mpfr_free_cache2
- See:
mpfr_free_pool
- See:
mpfr_free_str
- See:
mpfr_frexp
- See:
mpfr_gamma
- See:
mpfr_gamma_inc
- See:
mpfr_get_d
- See:
mpfr_get_d_2exp
- See:
mpfr_get_emax
- See:
mpfr_get_emax_max
- See:
mpfr_get_emax_min
- See:
mpfr_get_emin
- See:
mpfr_get_emin_max
- See:
mpfr_get_emin_min
- See:
mpfr_get_exp
- See:
mpfr_get_f
- See:
mpfr_get_flt
- See:
mpfr_get_patches
- See:
mpfr_get_prec
- See:
mpfr_get_q
- See:
mpfr_get_si
- See:
mpfr_get_sj
- See:
mpfr_get_str
- See:
mpfr_get_str_ndigits
- See:
mpfr_get_ui
- See:
mpfr_get_uj
- See:
mpfr_get_version
- See:
mpfr_get_z
- See:
mpfr_get_z_2exp
- grandom⚠DeprecatedSee:
mpfr_grandom
- See:
mpfr_greater_p
- See:
mpfr_greaterequal_p
- See:
mpfr_hypot
- See:
mpfr_inexflag_p
- See:
mpfr_inf_p
- init⚠See:
mpfr_init
- See:
mpfr_init2
- See:
mpfr_init_set
- See:
mpfr_init_set_d
- See:
mpfr_init_set_f
- See:
mpfr_init_set_q
- See:
mpfr_init_set_si
- See:
mpfr_init_set_str
- See:
mpfr_init_set_ui
- See:
mpfr_init_set_z
- See:
mpfr_inits
- See:
mpfr_inits2
- See:
mpfr_inp_str
- See:
mpfr_integer_p
- j0⚠See:
mpfr_j0
- j1⚠See:
mpfr_j1
- jn⚠See:
mpfr_jn
- See:
mpfr_less_p
- See:
mpfr_lessequal_p
- See:
mpfr_lessgreater_p
- See:
mpfr_lgamma
- li2⚠See:
mpfr_li2
- See:
mpfr_lngamma
- log⚠See:
mpfr_log
- See:
mpfr_log1p
- log2⚠See:
mpfr_log2
- See:
mpfr_log2p1
- See:
mpfr_log10
- See:
mpfr_log10p1
- See:
mpfr_log_ui
- max⚠See:
mpfr_max
- min⚠See:
mpfr_min
- See:
mpfr_min_prec
- modf⚠See:
mpfr_modf
- mul⚠See:
mpfr_mul
- See:
mpfr_mul_2exp
- See:
mpfr_mul_2si
- See:
mpfr_mul_2ui
- See:
mpfr_mul_d
- See:
mpfr_mul_q
- See:
mpfr_mul_si
- See:
mpfr_mul_ui
- See:
mpfr_mul_z
- See:
mpfr_nan_p
- See:
mpfr_nanflag_p
- neg⚠See:
mpfr_neg
- See:
mpfr_nextabove
- See:
mpfr_nextbelow
- See:
mpfr_nexttoward
- See:
mpfr_nrandom
- See:
mpfr_number_p
- See:
mpfr_out_str
- See:
mpfr_overflow_p
- pow⚠See:
mpfr_pow
- See:
mpfr_pow_si
- See:
mpfr_pow_sj
- See:
mpfr_pow_ui
- See:
mpfr_pow_uj
- See:
mpfr_pow_z
- pown⚠See:
mpfr_pown
- powr⚠See:
mpfr_powr
- See:
mpfr_prec_round
- See:
mpfr_print_rnd_mode
- See:
mpfr_printf
- See:
mpfr_rec_sqrt
- See:
mpfr_regular_p
- See:
mpfr_reldiff
- See:
mpfr_remainder
- See:
mpfr_remquo
- rint⚠See:
mpfr_rint
- See:
mpfr_rint_ceil
- See:
mpfr_rint_floor
- See:
mpfr_rint_round
- See:
mpfr_rint_roundeven
- See:
mpfr_rint_trunc
- root⚠DeprecatedSee:
mpfr_root
- See:
mpfr_rootn_si
- See:
mpfr_rootn_ui
- See:
mpfr_round
- See:
mpfr_roundeven
- sec⚠See:
mpfr_sec
- sech⚠See:
mpfr_sech
- set⚠See:
mpfr_set
- See:
mpfr_set_d
- See:
mpfr_set_divby0
- See:
mpfr_set_emax
- See:
mpfr_set_emin
- See:
mpfr_set_erangeflag
- See:
mpfr_set_exp
- See:
mpfr_set_f
- See:
mpfr_set_flt
- See:
mpfr_set_inexflag
- See:
mpfr_set_inf
- See:
mpfr_set_nan
- See:
mpfr_set_nanflag
- See:
mpfr_set_overflow
- See:
mpfr_set_prec
- See:
mpfr_set_prec_raw
- See:
mpfr_set_q
- See:
mpfr_set_si
- See:
mpfr_set_si_2exp
- See:
mpfr_set_sj
- See:
mpfr_set_sj_2exp
- See:
mpfr_set_str
- See:
mpfr_set_ui
- See:
mpfr_set_ui_2exp
- See:
mpfr_set_uj
- See:
mpfr_set_uj_2exp
- See:
mpfr_set_underflow
- See:
mpfr_set_z
- See:
mpfr_set_z_2exp
- See:
mpfr_set_zero
- See:
mpfr_setsign
- sgn⚠See:
mpfr_sgn
- See:
mpfr_si_div
- See:
mpfr_si_sub
- See:
mpfr_signbit
- sin⚠See:
mpfr_sin
- See:
mpfr_sin_cos
- sinh⚠See:
mpfr_sinh
- See:
mpfr_sinh_cosh
- See:
mpfr_sinpi
- sinu⚠See:
mpfr_sinu
- See:
mpfr_snprintf
- See:
mpfr_sprintf
- sqr⚠See:
mpfr_sqr
- sqrt⚠See:
mpfr_sqrt
- See:
mpfr_sqrt_ui
- See:
mpfr_strtofr
- sub⚠See:
mpfr_sub
- See:
mpfr_sub_d
- See:
mpfr_sub_q
- See:
mpfr_sub_si
- See:
mpfr_sub_ui
- See:
mpfr_sub_z
- See:
mpfr_subnormalize
- sum⚠See:
mpfr_sum
- swap⚠See:
mpfr_swap
- tan⚠See:
mpfr_tan
- tanh⚠See:
mpfr_tanh
- See:
mpfr_tanpi
- tanu⚠See:
mpfr_tanu
- See:
mpfr_total_order_p
- See:
mpfr_trunc
- See:
mpfr_ui_div
- See:
mpfr_ui_pow
- See:
mpfr_ui_pow_ui
- See:
mpfr_ui_sub
- See:
mpfr_underflow_p
- See:
mpfr_unordered_p
- See:
mpfr_urandom
- See:
mpfr_urandomb
- y0⚠See:
mpfr_y0
- y1⚠See:
mpfr_y1
- yn⚠See:
mpfr_yn
- See:
mpfr_z_sub
- See:
mpfr_zero_p
- zeta⚠See:
mpfr_zeta
- See:
mpfr_zeta_ui
Type Aliases§
- See:
mpfr_flags_t
- See:
mpfr_prec_t