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 |
Enums
rnd_t | See: |
Constants
Functions
Type Definitions
exp_t | |
flags_t | See: |
prec_t | See: |