This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] Fix formatting of denormal IBM long double numbers


On Tue, Apr 24, 2012 at 12:23 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Â Â Â Â[BZ #13941]
> Â Â Â Â* sysdeps/ieee754/ldbl-128ibm/ldbl2mpn.c
> Â Â Â Â(__mpn_extract_long_double): Use DBL_MIN_EXP instead of
> Â Â Â ÂLDBL_MIN_EXP.
> Â Â Â Â* stdio-common/Makefile (tests): Add tst-sprintf3.
> Â Â Â Â* stdio-common/tst-sprintf3.c: New file.
>
> diff --git a/stdio-common/Makefile b/stdio-common/Makefile
> index 8cf6335..7519bc1 100644
> --- a/stdio-common/Makefile
> +++ b/stdio-common/Makefile
> @@ -56,7 +56,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
> Â Â Â Â tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 bug18 bug18a \
> Â Â Â Â bug19 bug19a tst-popen2 scanf13 scanf14 scanf15 bug20 bug21 bug22 \
> Â Â Â Â scanf16 scanf17 tst-setvbuf1 tst-grouping bug23 bug24 \
> - Â Â Â Âbug-vfprintf-nargs tst-long-dbl-fphex tst-fphex-wide
> + Â Â Â Âbug-vfprintf-nargs tst-long-dbl-fphex tst-fphex-wide tst-sprintf3
>
> Âtest-srcs = tst-unbputc tst-printf
>
> diff --git a/stdio-common/tst-sprintf3.c b/stdio-common/tst-sprintf3.c
> new file mode 100644
> index 0000000..4be24b0
> --- /dev/null
> +++ b/stdio-common/tst-sprintf3.c
> @@ -0,0 +1,71 @@
> +#include <float.h>
> +#include <math.h>
> +#include <stdio.h>
> +#include <string.h>
> +
> +int
> +main (void)
> +{
> +#if LDBL_MANT_DIG >= 106
> + Âvolatile union { long double l; long long x[2]; } u, v;
> + Âchar buf[64];
> +#endif
> + Âint result = 0;
> +
> +#if LDBL_MANT_DIG == 106 || LDBL_MANT_DIG == 113
> +# define COMPARE_LDBL(u, v) \
> + Â((u).l == (v).l && (u).x[0] == (v).x[0] && (u).x[1] == (v).x[1])
> +#else
> +# define COMPARE_LDBL(u, v) ((u).l == (v).l)
> +#endif
> +
> +#define TEST(val) \
> + Âdo                                   Â\
> + Â Â{ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Âu.l = (val); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Âsnprintf (buf, sizeof buf, "%.30LgL", u.l); Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Âif (strcmp (buf, #val) != 0) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â printf ("Error on line %d: %s != %s\n", __LINE__, buf, #val); Â Â\
> + Â Â Â Â result = 1; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â } Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Âif (sscanf (#val, "%Lg", &v.l) != 1 || !COMPARE_LDBL (u, v)) Â Â Â Â\
> + Â Â Â { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â printf ("Error sscanf on line %d: %.30Lg != %.30Lg\n", __LINE__, \
> + Â Â Â Â Â Â Â Â u.l, v.l); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â result = 1; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â } Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â/* printf ("%s %Lg %016Lx %016Lx\n", #val, u.l, u.x[0], u.x[1]); */ Â\
> + Â Â} Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Âwhile (0)
> +
> +#if LDBL_MANT_DIG >= 106
> +# if LDBL_MANT_DIG == 106
> + ÂTEST (2.22507385850719347803989925739e-308L);
> + ÂTEST (2.22507385850719397210554509863e-308L);
> + ÂTEST (2.22507385850720088902458687609e-308L);
> +# endif
> + ÂTEST (2.22507385850720138309023271733e-308L);
> + ÂTEST (2.22507385850720187715587855858e-308L);
> + ÂTEST (2.2250738585074419930597574044e-308L);
> + ÂTEST (4.45014771701440227211481959342e-308L);
> + ÂTEST (4.45014771701440276618046543466e-308L);
> + ÂTEST (4.45014771701440375431175711716e-308L);
> + ÂTEST (4.45014771701440474244304879965e-308L);
> + ÂTEST (7.12023634722304600689881138745e-307L);
> + ÂTEST (1.13923781555569064960474854133e-305L);
> + ÂTEST (1.13777777777777776389998996996L);
> + ÂTEST (1.13777777777777765287768750745L);
> + ÂTEST (20988295479420645138.2044444444L);
> + ÂTEST (20988295479420643090.2044444444L);
> + ÂTEST (2.14668699894294423266045294316e-292L);
> +# if LDBL_MANT_DIG == 106
> + ÂTEST (-2.35993711055432139266626434123e-292L);
> + ÂTEST (6.26323524637968345414769634658e-302L);
> + ÂTEST (1.49327164802066885331814201989e-308L);
> + ÂTEST (3.71834550652787023640837473722e-308L);
> + ÂTEST (9.51896449671134907001349268087e-306L);
> +# endif
> +#endif
> + Âreturn result;
> +}
> diff --git a/sysdeps/ieee754/ldbl-128ibm/ldbl2mpn.c b/sysdeps/ieee754/ldbl-128ibm/ldbl2mpn.c
> index 3162bbd..e65366d 100644
> --- a/sysdeps/ieee754/ldbl-128ibm/ldbl2mpn.c
> +++ b/sysdeps/ieee754/ldbl-128ibm/ldbl2mpn.c
> @@ -1,5 +1,4 @@
> -/* Copyright (C) 1995,1996,1997,1998,1999,2002,2003,2006
> - Â Â Â Free Software Foundation, Inc.
> +/* Copyright (C) 1995-2012 Free Software Foundation, Inc.
> Â ÂThis file is part of the GNU C Library.
>
> Â ÂThe GNU C Library is free software; you can redistribute it and/or
> @@ -104,7 +103,10 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
> Â Â Â else
> Â Â Â Â{
> Â Â Â Â Â/* It is a denormal number, meaning it has no implicit leading
> - Â Â Â Â Â Âone bit, and its exponent is in fact the format minimum. Â*/
> + Â Â Â Â Â Âone bit, and its exponent is in fact the format minimum. ÂWe
> + Â Â Â Â Â Âuse DBL_MIN_EXP instead of LDBL_MIN_EXP below because the
> + Â Â Â Â Â Âlatter describes the properties of the both parts together,
> + Â Â Â Â Â Âbut the exponent is computed from the high part only. Â*/
> Â Â Â Â Âint cnt;
>
> Â#if N == 2
> @@ -115,7 +117,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
> Â Â Â Â Â Â Âres_ptr[N - 1] = res_ptr[N - 1] << cnt
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | (res_ptr[0] >> (BITS_PER_MP_LIMB - cnt));
> Â Â Â Â Â Â Âres_ptr[0] <<= cnt;
> - Â Â Â Â Â Â *expt = LDBL_MIN_EXP - 1 - cnt;
> + Â Â Â Â Â Â *expt = DBL_MIN_EXP - 1 - cnt;
> Â Â Â Â Â Â}
> Â Â Â Â Âelse
> Â Â Â Â Â Â{
> @@ -130,7 +132,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
> Â Â Â Â Â Â Â Â Âres_ptr[N - 1] = res_ptr[0] >> (NUM_LEADING_ZEROS - cnt);
> Â Â Â Â Â Â Â Â Âres_ptr[0] <<= BITS_PER_MP_LIMB - (NUM_LEADING_ZEROS - cnt);
> Â Â Â Â Â Â Â Â}
> - Â Â Â Â Â Â *expt = LDBL_MIN_EXP - 1
> + Â Â Â Â Â Â *expt = DBL_MIN_EXP - 1
> Â Â Â Â Â Â Â Â- (BITS_PER_MP_LIMB - NUM_LEADING_ZEROS) - cnt;
> Â Â Â Â Â Â}
> Â#else
> @@ -161,7 +163,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
>
> Â Â Â Â Âfor (; k >= 0; k--)
> Â Â Â Â Â Âres_ptr[k] = 0;
> - Â Â Â Â *expt = LDBL_MIN_EXP - 1 - l * BITS_PER_MP_LIMB - cnt;
> + Â Â Â Â *expt = DBL_MIN_EXP - 1 - l * BITS_PER_MP_LIMB - cnt;
> Â#endif
> Â Â Â Â}
> Â Â }
> --
> 1.7.10

I'm fine with the fix.. but regarding the testcase, I think Roland
wants a license header in new test files.

Ryan S. Arnold

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]