summaryrefslogtreecommitdiff
path: root/src/get_z.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/get_z.c')
-rw-r--r--src/get_z.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/get_z.c b/src/get_z.c
index 68249a465..3c4811735 100644
--- a/src/get_z.c
+++ b/src/get_z.c
@@ -29,6 +29,7 @@ mpfr_get_z (mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t rnd)
int inex;
mpfr_t r;
mpfr_exp_t exp;
+ MPFR_SAVE_EXPO_DECL (expo);
if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
{
@@ -41,6 +42,8 @@ mpfr_get_z (mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t rnd)
return 0;
}
+ MPFR_SAVE_EXPO_MARK (expo);
+
exp = MPFR_GET_EXP (f);
/* if exp <= 0, then |f|<1, thus |o(f)|<=1 */
MPFR_ASSERTN (exp < 0 || exp <= MPFR_PREC_MAX);
@@ -50,6 +53,11 @@ mpfr_get_z (mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t rnd)
MPFR_ASSERTN (inex != 1 && inex != -1); /* integral part of f is
representable in r */
MPFR_ASSERTN (MPFR_IS_FP (r));
+
+ /* The flags from mpfr_rint are the wanted ones. In particular,
+ it sets the inexact flag when necessary. */
+ MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
+
exp = mpfr_get_z_2exp (z, r);
if (exp >= 0)
mpz_mul_2exp (z, z, exp);
@@ -57,5 +65,7 @@ mpfr_get_z (mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t rnd)
mpz_fdiv_q_2exp (z, z, -exp);
mpfr_clear (r);
+ MPFR_SAVE_EXPO_FREE (expo);
+
return inex;
}