int mpfr_set_sj_2exp (mpfr_t x, intmax_t j, intmax_t e, mp_rnd_t rnd) { if (j>=0) return mpfr_set_uj_2exp (x, j, e, rnd); else { int inex; inex = mpfr_set_uj_2exp (x, - (uintmax_t) j, e, MPFR_INVERT_RND (rnd)); MPFR_CHANGE_SIGN (x); return -inex; } }
static void check_set_uj_2exp (void) { mpfr_t x; int inex; mpfr_init2 (x, sizeof(uintmax_t)*CHAR_BIT); inex = mpfr_set_uj_2exp (x, 1, 0, MPFR_RNDN); if (inex || mpfr_cmp_ui(x, 1)) ERROR("(1U,0)"); inex = mpfr_set_uj_2exp (x, 1024, -10, MPFR_RNDN); if (inex || mpfr_cmp_ui(x, 1)) ERROR("(1024U,-10)"); inex = mpfr_set_uj_2exp (x, 1024, 10, MPFR_RNDN); if (inex || mpfr_cmp_ui(x, 1024L * 1024L)) ERROR("(1024U,+10)"); inex = mpfr_set_uj_2exp (x, MPFR_UINTMAX_MAX, 1000, MPFR_RNDN); inex |= mpfr_div_2ui (x, x, 1000, MPFR_RNDN); inex |= mpfr_add_ui (x, x, 1, MPFR_RNDN); if (inex || !mpfr_powerof2_raw (x) || MPFR_EXP (x) != (sizeof(uintmax_t)*CHAR_BIT+1) ) ERROR("(UINTMAX_MAX)"); inex = mpfr_set_uj_2exp (x, MPFR_UINTMAX_MAX, MPFR_EMAX_MAX-10, MPFR_RNDN); if (inex == 0 || !mpfr_inf_p (x)) ERROR ("Overflow"); inex = mpfr_set_uj_2exp (x, MPFR_UINTMAX_MAX, MPFR_EMIN_MIN-1000, MPFR_RNDN); if (inex == 0 || !MPFR_IS_ZERO (x)) ERROR ("Underflow"); mpfr_clear (x); }
int mpfr_set_uj (mpfr_t x, uintmax_t j, mp_rnd_t rnd) { return mpfr_set_uj_2exp (x, j, 0, rnd); }