diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-12-27 19:20:53 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-12-27 19:21:19 +0000 |
commit | 68e2fa8ed9dbf0edfdaed0310801e764c12af46e (patch) | |
tree | 101f4c8b7ec20470739855bc4cf0cc4fb01f6f4b /stdio-common/printf_fphex.c | |
parent | f1018448e82ec658352d1dc6cefb65b70f564cad (diff) | |
parent | 8d59503b977070aaa4e504e8d6dcb7da3711893e (diff) |
Merge commit 'refs/top-bases/t/gsync-libc' into t/gsync-libc
Diffstat (limited to 'stdio-common/printf_fphex.c')
-rw-r--r-- | stdio-common/printf_fphex.c | 145 |
1 files changed, 66 insertions, 79 deletions
diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c index 255c7e0372..df3956316d 100644 --- a/stdio-common/printf_fphex.c +++ b/stdio-common/printf_fphex.c @@ -1,5 +1,5 @@ /* Print floating point number in hexadecimal notation according to ISO C99. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -17,6 +17,7 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ +#include <array_length.h> #include <ctype.h> #include <ieee754.h> #include <math.h> @@ -31,21 +32,24 @@ #include <stdbool.h> #include <rounding-mode.h> +#if __HAVE_DISTINCT_FLOAT128 +# include "ieee754_float128.h" +# include <ldbl-128/printf_fphex_macros.h> +# define PRINT_FPHEX_FLOAT128 \ + PRINT_FPHEX (_Float128, fpnum.flt128, ieee854_float128, \ + IEEE854_FLOAT128_BIAS) +#endif + /* #define NDEBUG 1*/ /* Undefine this for debugging assertions. */ #include <assert.h> -/* This defines make it possible to use the same code for GNU C library and - the GNU I/O library. */ #include <libioP.h> #define PUT(f, s, n) _IO_sputn (f, s, n) #define PAD(f, c, n) (wide ? _IO_wpadn (f, c, n) : _IO_padn (f, c, n)) -/* We use this file GNU C library and GNU I/O library. So make - names equal. */ #undef putc #define putc(c, f) (wide \ ? (int)_IO_putwc_unlocked (c, f) : _IO_putc_unlocked (c, f)) -#define size_t _IO_size_t -#define FILE _IO_FILE + /* Macros for doing the actual output. */ @@ -94,6 +98,9 @@ __printf_fphex (FILE *fp, { union ieee754_double dbl; long double ldbl; +#if __HAVE_DISTINCT_FLOAT128 + _Float128 flt128; +#endif } fpnum; @@ -157,82 +164,57 @@ __printf_fphex (FILE *fp, /* The decimal point character must never be zero. */ assert (*decimal != '\0' && decimalwc != L'\0'); +#define PRINTF_FPHEX_FETCH(FLOAT, VAR) \ + { \ + (VAR) = *(const FLOAT *) args[0]; \ + \ + /* Check for special values: not a number or infinity. */ \ + if (isnan (VAR)) \ + { \ + if (isupper (info->spec)) \ + { \ + special = "NAN"; \ + wspecial = L"NAN"; \ + } \ + else \ + { \ + special = "nan"; \ + wspecial = L"nan"; \ + } \ + } \ + else \ + { \ + if (isinf (VAR)) \ + { \ + if (isupper (info->spec)) \ + { \ + special = "INF"; \ + wspecial = L"INF"; \ + } \ + else \ + { \ + special = "inf"; \ + wspecial = L"inf"; \ + } \ + } \ + } \ + negative = signbit (VAR); \ + } /* Fetch the argument value. */ +#if __HAVE_DISTINCT_FLOAT128 + if (info->is_binary128) + PRINTF_FPHEX_FETCH (_Float128, fpnum.flt128) + else +#endif #ifndef __NO_LONG_DOUBLE_MATH if (info->is_long_double && sizeof (long double) > sizeof (double)) - { - fpnum.ldbl = *(const long double *) args[0]; - - /* Check for special values: not a number or infinity. */ - if (isnan (fpnum.ldbl)) - { - if (isupper (info->spec)) - { - special = "NAN"; - wspecial = L"NAN"; - } - else - { - special = "nan"; - wspecial = L"nan"; - } - } - else - { - if (isinf (fpnum.ldbl)) - { - if (isupper (info->spec)) - { - special = "INF"; - wspecial = L"INF"; - } - else - { - special = "inf"; - wspecial = L"inf"; - } - } - } - negative = signbit (fpnum.ldbl); - } + PRINTF_FPHEX_FETCH (long double, fpnum.ldbl) else -#endif /* no long double */ - { - fpnum.dbl.d = *(const double *) args[0]; +#endif + PRINTF_FPHEX_FETCH (double, fpnum.dbl.d) - /* Check for special values: not a number or infinity. */ - if (isnan (fpnum.dbl.d)) - { - if (isupper (info->spec)) - { - special = "NAN"; - wspecial = L"NAN"; - } - else - { - special = "nan"; - wspecial = L"nan"; - } - } - else - { - if (isinf (fpnum.dbl.d)) - { - if (isupper (info->spec)) - { - special = "INF"; - wspecial = L"INF"; - } - else - { - special = "inf"; - wspecial = L"inf"; - } - } - } - negative = signbit (fpnum.dbl.d); - } +#undef PRINTF_FPHEX_FETCH if (special) { @@ -260,6 +242,11 @@ __printf_fphex (FILE *fp, return done; } +#if __HAVE_DISTINCT_FLOAT128 + if (info->is_binary128) + PRINT_FPHEX_FLOAT128; + else +#endif if (info->is_long_double == 0 || sizeof (double) == sizeof (long double)) { /* We have 52 bits of mantissa plus one implicit digit. Since @@ -329,8 +316,8 @@ __printf_fphex (FILE *fp, /* Look for trailing zeroes. */ if (! zero_mantissa) { - wnumend = &wnumbuf[sizeof wnumbuf / sizeof wnumbuf[0]]; - numend = &numbuf[sizeof numbuf / sizeof numbuf[0]]; + wnumend = array_end (wnumbuf); + numend = array_end (numbuf); while (wnumend[-1] == L'0') { --wnumend; |