summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2008-01-04 21:57:08 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2008-01-04 21:57:08 +0000
commit94c07fa326286d7007f85f665315269e494a89ee (patch)
tree6ad7977f9588cf996f9f234d5a4dd7963df5a051
parentc9da5c3da9faa7fd86e4ce1185962b323959b2b7 (diff)
downloadmpfr-94c07fa326286d7007f85f665315269e494a89ee.tar.gz
Fixed return value of mpfr_strtofr in case of invalid data (it was -1,
but it should be 0 since it is a ternary value and the result is 0, which is exact). Added test of the ternary value in this case. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@5173 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--strtofr.c4
-rw-r--r--tests/tstrtofr.c7
2 files changed, 8 insertions, 3 deletions
diff --git a/strtofr.c b/strtofr.c
index 7839e8c03..499655656 100644
--- a/strtofr.c
+++ b/strtofr.c
@@ -731,7 +731,9 @@ mpfr_strtofr (mpfr_t x, const char *string, char **end, int base,
res = parse_string (x, &pstr, &string, base);
/* If res == 0, then it was exact (NAN or INF),
so it is also the ternary value */
- if (res == 1)
+ if (MPFR_UNLIKELY (res == -1)) /* invalid data */
+ res = 0; /* x is set to 0, which is exact, thus ternary value is 0 */
+ else if (res == 1)
{
res = parsed_string_to_mpfr (x, &pstr, rnd);
free_parsed_string (&pstr);
diff --git a/tests/tstrtofr.c b/tests/tstrtofr.c
index b099ba5d3..f0cf7ade8 100644
--- a/tests/tstrtofr.c
+++ b/tests/tstrtofr.c
@@ -603,26 +603,29 @@ check_parse (void)
{
mpfr_t x;
char *s;
+ int res;
mpfr_init (x);
/* Invalid data */
mpfr_set_si (x, -1, GMP_RNDN);
- mpfr_strtofr (x, " invalid", NULL, 10, GMP_RNDN);
+ res = mpfr_strtofr (x, " invalid", NULL, 10, GMP_RNDN);
if (MPFR_NOTZERO (x) || MPFR_IS_NEG (x))
{
printf ("Failed parsing ' invalid' (1)\n X=");
mpfr_dump (x);
exit (1);
}
+ MPFR_ASSERTN (res == 0);
mpfr_set_si (x, -1, GMP_RNDN);
- mpfr_strtofr (x, " invalid", &s, 0, GMP_RNDN);
+ res = mpfr_strtofr (x, " invalid", &s, 0, GMP_RNDN);
if (MPFR_NOTZERO (x) || MPFR_IS_NEG (x) || strcmp (s, " invalid"))
{
printf ("Failed parsing ' invalid' (2)\n S=%s\n X=", s);
mpfr_dump (x);
exit (1);
}
+ MPFR_ASSERTN (res == 0);
/* Check if it stops correctly */
mpfr_strtofr (x, "15*x", &s, 10, GMP_RNDN);
if (mpfr_cmp_ui (x, 15) || strcmp (s, "*x"))