Skip to content

Commit

Permalink
Added functions creating Mpfr from integer and exponent
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk20 committed Jun 29, 2015
1 parent 38f95e1 commit 29583cb
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/mpfr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use libc::{c_char, c_int, c_ulong, c_long, c_double, c_void};
use libc::{c_int, c_ulong, c_long, c_double, c_void};
use gmp::mpz::{Mpz, mpz_ptr, mpz_srcptr};
use gmp::mpq::{Mpq, mpq_srcptr};
use gmp::mpf::{Mpf, mpf_ptr, mpf_srcptr};
Expand Down Expand Up @@ -99,6 +99,30 @@ impl Mpfr {
}
}

pub fn new_u64_2exp(base: u64, exp: i32) -> Mpfr {
unsafe {
let mut mpfr = Mpfr::new(Mpfr::get_default_prec());
mpfr_set_ui_2exp(&mut mpfr.mpfr, base as c_ulong, exp as mpfr_exp_t, mpfr_rnd_t::MPFR_RNDN);
mpfr
}
}

pub fn new_i64_2exp(base: i64, exp: i32) -> Mpfr {
unsafe {
let mut mpfr = Mpfr::new(Mpfr::get_default_prec());
mpfr_set_si_2exp(&mut mpfr.mpfr, base as c_long, exp as mpfr_exp_t, mpfr_rnd_t::MPFR_RNDN);
mpfr
}
}

pub fn new_mpz_2exp(base: &Mpz, exp: i32) -> Mpfr {
unsafe {
let mut mpfr = Mpfr::new(Mpfr::get_default_prec());
mpfr_set_z_2exp(&mut mpfr.mpfr, &base.mpz, exp as mpfr_exp_t, mpfr_rnd_t::MPFR_RNDN);
mpfr
}
}

pub fn zero(sign: i32) -> Mpfr {
unsafe {
let mut mpfr = Mpfr::new(Mpfr::get_default_prec());
Expand Down

0 comments on commit 29583cb

Please sign in to comment.