From 76014a241d9a7e4c2372b3db3a23f00f7f630055 Mon Sep 17 00:00:00 2001 From: hanrot Date: Mon, 24 Feb 2003 12:32:56 +0000 Subject: Replaced NaN, Inf by @NaN@, @Inf@ [for bases > 24]. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2249 280ebfd0-de03-0410-8827-d642c229c3f4 --- dump.c | 6 +++--- get_str.c | 8 ++++---- out_str.c | 6 +++--- print_raw.c | 4 ++-- set_str.c | 8 ++------ tests/tget_str.c | 6 +++--- tests/tset_str.c | 8 ++++---- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/dump.c b/dump.c index e6786c295..cf34f9eed 100644 --- a/dump.c +++ b/dump.c @@ -35,16 +35,16 @@ mpfr_dump (mpfr_srcptr u, mp_rnd_t rnd_mode) if (MPFR_IS_NAN(u)) { - printf ("NaN\n"); + printf ("@NaN@\n"); return; } if (MPFR_IS_INF(u)) { if (MPFR_SIGN(u) == 1) - printf ("Inf\n"); + printf ("@Inf@\n"); else - printf ("-Inf\n"); + printf ("-@Inf@\n"); return; } diff --git a/get_str.c b/get_str.c index b1c6aa92d..f8b6102fe 100644 --- a/get_str.c +++ b/get_str.c @@ -560,8 +560,8 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd if (MPFR_IS_NAN(x)) { if (s == NULL) - s = (char*) (*__gmp_allocate_func) (4); - strcpy (s, "NaN"); + s = (char*) (*__gmp_allocate_func) (6); + strcpy (s, "@NaN@"); return s; } @@ -570,8 +570,8 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd if (MPFR_IS_INF(x)) { if (s == NULL) - s = (char*) (*__gmp_allocate_func) (neg + 4); - strcpy (s, (neg) ? "-Inf" : "Inf"); + s = (char*) (*__gmp_allocate_func) (neg + 6); + strcpy (s, (neg) ? "-@Inf@" : "@Inf@"); return s; } diff --git a/out_str.c b/out_str.c index df638ff7e..059253b50 100644 --- a/out_str.c +++ b/out_str.c @@ -37,7 +37,7 @@ mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op, if (MPFR_IS_NAN(op)) { - fprintf (stream, "NaN"); + fprintf (stream, "@NaN@"); return 3; } @@ -45,12 +45,12 @@ mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op, { if (MPFR_SIGN(op) > 0) { - fprintf (stream, "Inf"); + fprintf (stream, "@Inf@"); return 3; } else { - fprintf (stream, "-Inf"); + fprintf (stream, "-@Inf@"); return 4; } } diff --git a/print_raw.c b/print_raw.c index 06617fab4..4622ff764 100644 --- a/print_raw.c +++ b/print_raw.c @@ -64,9 +64,9 @@ mpfr_print_binary (mpfr_srcptr x) char *str; unsigned long alloc_size; - if (MPFR_IS_NAN(x)) printf("NaN"); + if (MPFR_IS_NAN(x)) printf("@NaN@"); else if (MPFR_IS_INF(x)) { - if (MPFR_SIGN(x) == 1) { printf("Inf"); } else printf("-Inf"); + if (MPFR_SIGN(x) == 1) { printf("@Inf@"); } else printf("-@Inf@"); } else if (!MPFR_NOTZERO(x)) { if (MPFR_SIGN(x) < 0) printf("-"); diff --git a/set_str.c b/set_str.c index 92f917efb..c177d4017 100644 --- a/set_str.c +++ b/set_str.c @@ -95,10 +95,7 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd) if (base < 2 || base > 36) return -1; - /* be careful that 'nan' is a valid number in base >= 24, - since n=23, a=10, n=23 */ - if (((base < 24) ? strncasecmp (str, "NaN", 3) : strncmp (str, "NaN", 3)) - == 0) + if (strlen(str) >= 5 && strncasecmp (str, "@NaN@", 5) == 0) { MPFR_SET_NAN(x); /* MPFR_RET_NAN not used as the return value isn't a ternary value */ @@ -113,8 +110,7 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd) /* be careful that 'inf' is a valid number in base >= 24, since i=18, n=23, f=15 */ - if (((base < 24) ? strncasecmp (str, "Inf", 3) : strncmp (str, "Inf", 3)) - == 0) + if (strlen(str) >= 3 && strncasecmp (str, "@Inf@", 5) == 0) { MPFR_CLEAR_NAN (x); MPFR_SET_INF (x); diff --git a/tests/tget_str.c b/tests/tget_str.c index dd573daa1..61e549866 100644 --- a/tests/tget_str.c +++ b/tests/tget_str.c @@ -216,7 +216,7 @@ check_large (void) mpfr_set_nan (x); s = mpfr_get_str (NULL, &e, 10, 1000, x, GMP_RNDN); - if (strcmp (s, "NaN")) + if (strcmp (s, "@NaN@")) { fprintf (stderr, "Error for NaN\n"); exit (1); @@ -227,7 +227,7 @@ check_large (void) mpfr_set_inf (x, 1); s = mpfr_get_str (NULL, &e, 10, 1000, x, GMP_RNDN); - if (strcmp (s, "Inf")) + if (strcmp (s, "@Inf@")) { fprintf (stderr, "Error for Inf\n"); exit (1); @@ -238,7 +238,7 @@ check_large (void) mpfr_set_inf (x, -1); s = mpfr_get_str (NULL, &e, 10, 1000, x, GMP_RNDN); - if (strcmp (s, "-Inf")) + if (strcmp (s, "-@Inf@")) { fprintf (stderr, "Error for -Inf\n"); exit (1); diff --git a/tests/tset_str.c b/tests/tset_str.c index 1abbcd0ab..e8a31f18e 100644 --- a/tests/tset_str.c +++ b/tests/tset_str.c @@ -169,27 +169,27 @@ main (int argc, char *argv[]) (*__gmp_free_func) (str, strlen (str) + 1); } - if (mpfr_set_str (x, "NaNgarbage", 10, GMP_RNDN) != 0 || !mpfr_nan_p(x)) + if (mpfr_set_str (x, "@NaN@garbage", 10, GMP_RNDN) != 0 || !mpfr_nan_p(x)) { fprintf (stderr, "mpfr_set_str failed on NaN\n"); exit (1); } - if (mpfr_set_str (x, "Infgarbage", 10, GMP_RNDN) != 0 || !mpfr_inf_p(x) || + if (mpfr_set_str (x, "@Inf@garbage", 10, GMP_RNDN) != 0 || !mpfr_inf_p(x) || MPFR_SIGN(x) < 0) { fprintf (stderr, "mpfr_set_str failed on Inf\n"); exit (1); } - if (mpfr_set_str (x, "-Infgarbage", 10, GMP_RNDN) != 0 || !mpfr_inf_p(x) || + if (mpfr_set_str (x, "-@Inf@garbage", 10, GMP_RNDN) != 0 || !mpfr_inf_p(x) || MPFR_SIGN(x) > 0) { fprintf (stderr, "mpfr_set_str failed on -Inf\n"); exit (1); } - if (mpfr_set_str (x, "+Infgarbage", 10, GMP_RNDN) != 0 || !mpfr_inf_p(x) || + if (mpfr_set_str (x, "+@Inf@garbage", 10, GMP_RNDN) != 0 || !mpfr_inf_p(x) || MPFR_SIGN(x) < 0) { fprintf (stderr, "mpfr_set_str failed on +Inf\n"); -- cgit v1.2.1