summaryrefslogtreecommitdiff
path: root/src/set_si_2exp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set_si_2exp.c')
-rw-r--r--src/set_si_2exp.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/set_si_2exp.c b/src/set_si_2exp.c
index e15c9b60f..6b8fa9cd1 100644
--- a/src/set_si_2exp.c
+++ b/src/set_si_2exp.c
@@ -40,6 +40,15 @@ mpfr_set_si_2exp (mpfr_ptr x, long i, mpfr_exp_t e, mpfr_rnd_t rnd_mode)
mp_limb_t ai, *xp;
int inex = 0;
+ /* Early underflow/overflow checking is necessary to avoid
+ integer overflow or errors due to special exponent values. */
+ if (MPFR_UNLIKELY (e < __gmpfr_emin - (mpfr_exp_t)
+ (sizeof (unsigned long) * CHAR_BIT + 1)))
+ return mpfr_underflow (x, rnd_mode == MPFR_RNDN ?
+ MPFR_RNDZ : rnd_mode, i < 0 ? -1 : 1);
+ if (MPFR_UNLIKELY (e >= __gmpfr_emax))
+ return mpfr_overflow (x, rnd_mode, i < 0 ? -1 : 1);
+
/* FIXME: support int limbs (e.g. 16-bit limbs on 16-bit proc) */
ai = SAFE_ABS (unsigned long, i);
MPFR_ASSERTN (SAFE_ABS (unsigned long, i) == ai);