/* Print size value using units for orders of magnitude.
- Copyright (C) 1997-2012 Free Software Foundation, Inc.
+ Copyright (C) 1997-2020 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Based on a proposal by Larry McVoy <lm@sgi.com>.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <ctype.h>
#include <ieee754.h>
#include <printf.h>
#include <libioP.h>
-
-/* This defines make it possible to use the same code for GNU C library and
- the GNU I/O library. */
#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
+
\f
/* Macros for doing the actual output. */
#define outchar(ch) \
do \
{ \
- register const int outc = (ch); \
+ const int outc = (ch); \
if (putc (outc, fp) == EOF) \
return -1; \
++done; \
#define PRINT(ptr, wptr, len) \
do \
{ \
- register size_t outlen = (len); \
+ size_t outlen = (len); \
if (len > 20) \
{ \
if (PUT (fp, wide ? (const char *) wptr : ptr, outlen) != outlen) \
union
{
union ieee754_double dbl;
- union ieee854_long_double ldbl;
+ long double ldbl;
+#if __HAVE_DISTINCT_FLOAT128
+ _Float128 f128;
+#endif
}
fpnum;
const void *ptr = &fpnum;
- int fpnum_sign = 0;
+ int is_neg = 0;
/* "NaN" or "Inf" for the special cases. */
const char *special = NULL;
struct printf_info fp_info;
int done = 0;
int wide = info->wide;
- int res;
+
+#define PRINTF_SIZE_FETCH(FLOAT, VAR) \
+ { \
+ (VAR) = *(const FLOAT *) args[0]; \
+ \
+ /* Check for special values: not a number or infinity. */ \
+ if (isnan (VAR)) \
+ { \
+ special = "nan"; \
+ wspecial = L"nan"; \
+ /* is_neg = 0; Already zero */ \
+ } \
+ else if (isinf (VAR)) \
+ { \
+ is_neg = signbit (VAR); \
+ special = "inf"; \
+ wspecial = L"inf"; \
+ } \
+ else \
+ while ((VAR) >= divisor && tag[1] != '\0') \
+ { \
+ (VAR) /= divisor; \
+ ++tag; \
+ } \
+ }
/* Fetch the argument value. */
+#if __HAVE_DISTINCT_FLOAT128
+ if (info->is_binary128)
+ PRINTF_SIZE_FETCH (_Float128, fpnum.f128)
+ else
+#endif
#ifndef __NO_LONG_DOUBLE_MATH
if (info->is_long_double && sizeof (long double) > sizeof (double))
- {
- fpnum.ldbl.d = *(const long double *) args[0];
-
- /* Check for special values: not a number or infinity. */
- if (__isnanl (fpnum.ldbl.d))
- {
- special = "nan";
- wspecial = L"nan";
- // fpnum_sign = 0; Already zero
- }
- else if ((res = __isinfl (fpnum.ldbl.d)))
- {
- fpnum_sign = res;
- special = "inf";
- wspecial = L"inf";
- }
- else
- while (fpnum.ldbl.d >= divisor && tag[1] != '\0')
- {
- fpnum.ldbl.d /= divisor;
- ++tag;
- }
- }
+ PRINTF_SIZE_FETCH (long double, fpnum.ldbl)
else
-#endif /* no long double */
- {
- fpnum.dbl.d = *(const double *) args[0];
+#endif
+ PRINTF_SIZE_FETCH (double, fpnum.dbl.d)
- /* Check for special values: not a number or infinity. */
- if (__isnan (fpnum.dbl.d))
- {
- special = "nan";
- wspecial = L"nan";
- // fpnum_sign = 0; Already zero
- }
- else if ((res = __isinf (fpnum.dbl.d)))
- {
- fpnum_sign = res;
- special = "inf";
- wspecial = L"inf";
- }
- else
- while (fpnum.dbl.d >= divisor && tag[1] != '\0')
- {
- fpnum.dbl.d /= divisor;
- ++tag;
- }
- }
+#undef PRINTF_SIZE_FETCH
if (special)
{
int width = info->prec > info->width ? info->prec : info->width;
- if (fpnum_sign < 0 || info->showsign || info->space)
+ if (is_neg || info->showsign || info->space)
--width;
width -= 3;
if (!info->left && width > 0)
PADN (' ', width);
- if (fpnum_sign < 0)
+ if (is_neg)
outchar ('-');
else if (info->showsign)
outchar ('+');