summaryrefslogtreecommitdiff
path: root/src/sqrt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sqrt.c')
-rw-r--r--src/sqrt.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/sqrt.c b/src/sqrt.c
index 048a54c..8f58cbc 100644
--- a/src/sqrt.c
+++ b/src/sqrt.c
@@ -48,6 +48,7 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
/* we need to know the sign of Im(b) when it is +/-0 */
const mpfr_rnd_t r = im_sgn ? MPFR_RNDD : MPFR_RNDU;
/* rounding mode used when computing t */
+ mpfr_exp_t saved_emin, saved_emax;
/* special values */
if (!mpc_fin_p (b)) {
@@ -202,6 +203,11 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
}
}
+ saved_emin = mpfr_get_emin ();
+ saved_emax = mpfr_get_emax ();
+ mpfr_set_emin (mpfr_get_emin_min ());
+ mpfr_set_emax (mpfr_get_emax_max ());
+
do
{
loops ++;
@@ -363,5 +369,11 @@ mpc_sqrt (mpc_ptr a, mpc_srcptr b, mpc_rnd_t rnd)
mpfr_clear (w);
mpfr_clear (t);
+ /* restore the exponent range, and check the range of results */
+ mpfr_set_emin (saved_emin);
+ mpfr_set_emax (saved_emax);
+ inex_re = mpfr_check_range (mpc_realref (a), inex_re, MPC_RND_RE (rnd));
+ inex_im = mpfr_check_range (mpc_imagref (a), inex_im, MPC_RND_IM (rnd));
+
return MPC_INEX (inex_re, inex_im);
}