diff options
author | Ulrich Drepper <drepper@redhat.com> | 1997-08-05 23:36:21 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1997-08-05 23:36:21 +0000 |
commit | 044b16f4e9ae773187f4fee8a9a0a54f9a51f13f (patch) | |
tree | 58bc41e16535e0d0f61d51e6af15ce4128864fc9 /stdio-common | |
parent | c59a94711c6a9d38811b828863076f39000831b4 (diff) |
update for 2.0.5pre1
Diffstat (limited to 'stdio-common')
-rw-r--r-- | stdio-common/bug3.c | 2 | ||||
-rw-r--r-- | stdio-common/bug4.c | 2 | ||||
-rw-r--r-- | stdio-common/printf_fp.c | 19 | ||||
-rw-r--r-- | stdio-common/tfformat.c | 10 | ||||
-rw-r--r-- | stdio-common/tstscanf.c | 34 | ||||
-rw-r--r-- | stdio-common/vfscanf.c | 25 |
6 files changed, 71 insertions, 21 deletions
diff --git a/stdio-common/bug3.c b/stdio-common/bug3.c index 3bb0158a21..3814d6ab75 100644 --- a/stdio-common/bug3.c +++ b/stdio-common/bug3.c @@ -7,7 +7,7 @@ DEFUN_VOID(main) { FILE *f; int i; - const char filename[] = "/tmp/bugtest"; + const char filename[] = "/tmp/bug3.test"; f = fopen(filename, "w+"); for (i=0; i<9000; i++) diff --git a/stdio-common/bug4.c b/stdio-common/bug4.c index 492a41d923..d6f92a307a 100644 --- a/stdio-common/bug4.c +++ b/stdio-common/bug4.c @@ -14,7 +14,7 @@ DEFUN(main, (argc, argv), FILE *f; int i; char buffer[31]; - const char filename[] = "/tmp/bugtest"; + const char filename[] = "/tmp/bug4.test"; while ((i = getopt (argc, argv, "rw")) != -1) switch (i) diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c index dede144b8d..49292e5b7c 100644 --- a/stdio-common/printf_fp.c +++ b/stdio-common/printf_fp.c @@ -1,5 +1,5 @@ /* Floating point output for `printf'. - Copyright (C) 1995, 1996 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. @@ -812,13 +812,24 @@ __printf_fp (FILE *fp, { char *tp = cp; - if (digit == '5') + if (digit == '5' && (*(cp - 1) & 1) == 0) /* This is the critical case. */ if (fracsize == 1 && frac[0] == 0) /* Rest of the number is zero -> round to even. (IEEE 754-1985 4.1 says this is the default rounding.) */ - if ((*(cp - 1) & 1) == 0) - goto do_expo; + goto do_expo; + else if (scalesize == 0) + { + /* Here we have to see whether all limbs are zero since no + normalization happened. */ + size_t lcnt = fracsize; + while (lcnt >= 1 && frac[lcnt - 1] == 0) + --lcnt; + if (lcnt == 0) + /* Rest of the number is zero -> round to even. + (IEEE 754-1985 4.1 says this is the default rounding.) */ + goto do_expo; + } if (fracdig_no > 0) { diff --git a/stdio-common/tfformat.c b/stdio-common/tfformat.c index cc9a3843cf..f00d0de253 100644 --- a/stdio-common/tfformat.c +++ b/stdio-common/tfformat.c @@ -14,7 +14,7 @@ sprint_double_type sprint_doubles[] = { {__LINE__, 30.3, "< +30.3>", "<%+15.10g>"}, {__LINE__, 10.0, "<10.00>", "<%5.2f>"}, - + {__LINE__, 1.002121970718271e+05, "100212.19707 ", "%0-15.5f"}, {__LINE__, -1.002121970718271e+05, "-100212.19707 ", "%0-15.5f"}, {__LINE__, 1.002121970718271e+05, "000100212.19707", "%015.5f"}, @@ -25,7 +25,7 @@ sprint_double_type sprint_doubles[] = {__LINE__, -1.002121970718271e+05, "-00100212.19707", "% 015.5f"}, {__LINE__, 1.002121970718271e+05, "+100212.19707 ", "%+-15.5f"}, {__LINE__, -1.002121970718271e+05, "-100212.19707 ", "%+-15.5f"}, - + {__LINE__, -1.002121970718271e+29, "-1.0E+29", "%.1E"}, {__LINE__, -1.002126048612756e-02, "-1.002126E-02", "%+#E"}, {__LINE__, -1.002653755271637e+00, "-1.00265", "%G"}, @@ -4005,7 +4005,11 @@ sprint_double_type sprint_doubles[] = #endif {__LINE__, 9.978034352999867e+15, "9.978034e+15", "%2.6e"}, {__LINE__, 9.998315286730175e-30, "9.998315e-30", "%6e"}, - + {__LINE__, 1.25, "1.2", "%.1f"}, + {__LINE__, 11.25, "11.2", "%.1f"}, + {__LINE__, 1.75, "1.8", "%.1f"}, + {__LINE__, 11.75, "11.8", "%.1f"}, + {0 } }; diff --git a/stdio-common/tstscanf.c b/stdio-common/tstscanf.c index d76d95b1b7..d0ff6c8b41 100644 --- a/stdio-common/tstscanf.c +++ b/stdio-common/tstscanf.c @@ -140,5 +140,39 @@ main (int argc, char **argv) if (out != stdout) pclose (out); + fputs ("Test 3:\n", out); + { + int res, val, n; + + res = sscanf ("-242", "%3o%n", &val, &n); + printf ("res = %d, val = %d, n = %d\n", res, val, n); + if (res != 1 || val != -20 || n != 3) + return 1; + } + + fputs ("Test 4:\n", out); + { + double a = 0, b = 0; + int res, n; + + res = sscanf ("1234567", "%3lg%3lg%n", &a, &b, &n); + printf ("res = %d, a = %g, b = %g, n = %d\n", res, a, b, n); + + if (res != 2 || a != 123 || b != 456 || n != 6) + return 1; + + res = sscanf ("0", "%lg", &a); + printf ("res = %d, a = %g\n", res, a); + + if (res != 1 || a != 0) + exit (EXIT_FAILURE); + + res = sscanf ("1e3", "%lg%n", &a, &n); + printf ("res = %d, a = %g, n = %d\n", res, a, n); + + if (res != 1 || a != 1000 || n != 3) + exit (EXIT_FAILURE); + } + exit(EXIT_SUCCESS); } diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c index 256f3eab33..cba6847266 100644 --- a/stdio-common/vfscanf.c +++ b/stdio-common/vfscanf.c @@ -54,8 +54,10 @@ # undef va_list # define va_list _IO_va_list -# define ungetc(c, s) (--read_in, _IO_ungetc (c, s)) -# define inchar() ((c = _IO_getc_unlocked (s)), (void) ++read_in, c) +# define ungetc(c, s) ((void) ((int) c != EOF && --read_in), \ + _IO_ungetc (c, s)) +# define inchar() ((c = _IO_getc_unlocked (s)), \ + (void) (c != EOF && ++read_in), c) # define encode_error() do { \ if (errp != NULL) *errp |= 4; \ _IO_funlockfile (s); \ @@ -98,8 +100,8 @@ _IO_flockfile (S) # define UNLOCK_STREAM __libc_cleanup_region_end (1) #else -# define ungetc(c, s) (--read_in, ungetc (c, s)) -# define inchar() ((c = getc (s)), (void) ++read_in, c) +# define ungetc(c, s) ((void) (c != EOF && --read_in), ungetc (c, s)) +# define inchar() ((c = getc (s)), (void) (c != EOF && ++read_in), c) # define encode_error() do { \ funlockfile (s); \ __set_errno (EILSEQ); \ @@ -717,9 +719,6 @@ __vfscanf (FILE *s, const char *format, va_list argptr) STRING_ADD_CHAR (str, c, char); } while ((width <= 0 || --width > 0) && inchar () != EOF); - if (c == EOF) - --read_in; - if (!(flags & SUPPRESS)) { *str = '\0'; @@ -943,14 +942,16 @@ __vfscanf (FILE *s, const char *format, va_list argptr) else if ((flags & GROUP) && c == thousands && !got_dot) ADDW (c); else - break; + { + /* The last read character is not part of the number + anymore. */ + ungetc (c, s); + break; + } if (width > 0) --width; } - while (inchar () != EOF && width != 0); - - /* The last read character is not part of the number anymore. */ - ungetc (c, s); + while (width != 0 && inchar () != EOF); if (wpsize == 0) conv_error (); |