summaryrefslogtreecommitdiff
path: root/set_str.c
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-23 09:43:29 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-23 09:43:29 +0000
commitdd160f2fbe5202834df211a9e58c123c701672c5 (patch)
tree7bdd316542b69039ab67a30ab5676e1168e7082b /set_str.c
parentea4528920a86d4d0569b796ffb90377acffb058d (diff)
downloadmpfr-dd160f2fbe5202834df211a9e58c123c701672c5.tar.gz
Improve coverage tests.
Fix 2 underflow bugs. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2783 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'set_str.c')
-rw-r--r--set_str.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/set_str.c b/set_str.c
index 6903618e5..aa6d70027 100644
--- a/set_str.c
+++ b/set_str.c
@@ -117,6 +117,8 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd)
return 0;
}
+ MPFR_CLEAR_FLAGS(x);
+
/* string "", "+" and "-" are invalid */
if (str[0] == '\0')
return -1;
@@ -184,7 +186,11 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd)
{
MPFR_SET_ZERO (x);
res = 0;
- goto sign_and_flags;
+ if (negative)
+ MPFR_SET_NEG(x);
+ else
+ MPFR_SET_POS(x);
+ goto end;
}
/* now we have str = 0.mant_s[0]...mant_s[prec_s-1]*base^exp_s*2^binexp */
@@ -359,14 +365,14 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd)
TMP_FREE(marker);
- MPFR_SET_EXP (x, exp_y + n * BITS_PER_MP_LIMB);
-
- sign_and_flags:
- MPFR_CLEAR_FLAGS(x);
+ /* Set sign of x before exp since check_range needs a valid sign */
if (negative)
MPFR_SET_NEG(x);
else
MPFR_SET_POS(x);
+ /* DO NOT USE MPFR_SET_EXP. The exp may be out of range! */
+ MPFR_EXP (x) = exp_y + n * BITS_PER_MP_LIMB;
+ res = mpfr_check_range (x, res, rnd );
end:
(*__gmp_free_func) (str1, size_str1 * sizeof (char));