diff options
author | Simon Josefsson <simon@josefsson.org> | 2007-04-16 13:25:26 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2007-04-16 13:25:26 +0000 |
commit | 567ef5a93bbb3b668ffeb418cc8ad02cfa8d692d (patch) | |
tree | 1e3be19a0761f177e5fb9506326e2771080880b3 /lgl/vasnprintf.c | |
parent | 0ccdb12231eefe5882e9409bba345617c0371acb (diff) | |
download | gnutls-567ef5a93bbb3b668ffeb418cc8ad02cfa8d692d.tar.gz |
Update.
Diffstat (limited to 'lgl/vasnprintf.c')
-rw-r--r-- | lgl/vasnprintf.c | 73 |
1 files changed, 27 insertions, 46 deletions
diff --git a/lgl/vasnprintf.c b/lgl/vasnprintf.c index 17f734e627..f30f29f368 100644 --- a/lgl/vasnprintf.c +++ b/lgl/vasnprintf.c @@ -54,14 +54,12 @@ #include "xsize.h" #if NEED_PRINTF_DIRECTIVE_A && !defined IN_LIBINTL -# include "float+.h" +# include <math.h> # include "isnan.h" # include "printf-frexp.h" -# if HAVE_LONG_DOUBLE -# include "isnanl-nolibm.h" -# include "printf-frexpl.h" -# include "fpucw.h" -# endif +# include "isnanl-nolibm.h" +# include "printf-frexpl.h" +# include "fpucw.h" #endif /* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ @@ -386,7 +384,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar } /* Allocate a temporary buffer of sufficient size. */ -# if HAVE_LONG_DOUBLE if (type == TYPE_LONGDOUBLE) tmp_length = (unsigned int) ((LDBL_DIG + 1) @@ -394,7 +391,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar ) + 1; /* turn floor into ceil */ else -# endif tmp_length = (unsigned int) ((DBL_DIG + 1) * 0.831 /* decimal -> hexadecimal */ @@ -427,7 +423,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar pad_ptr = NULL; p = tmp; -# if HAVE_LONG_DOUBLE if (type == TYPE_LONGDOUBLE) { long double arg = a.arg[dp->arg_index].a.a_longdouble; @@ -450,22 +445,11 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar BEGIN_LONG_DOUBLE_ROUNDING (); - if (arg < 0.0L) + if (signbit (arg)) /* arg < 0.0L or negative zero */ { sign = -1; arg = -arg; } - else if (arg == 0.0L) - { - /* Distinguish 0.0L and -0.0L. */ - static long double plus_zero = 0.0L; - long double arg_mem = arg; - if (memcmp (&plus_zero, &arg_mem, SIZEOF_LDBL) != 0) - { - sign = -1; - arg = -arg; - } - } if (sign < 0) *p++ = '-'; @@ -560,15 +544,15 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar } } *p++ = dp->conversion - 'A' + 'P'; -# if WIDE_CHAR_VERSION +# if WIDE_CHAR_VERSION { static const wchar_t decimal_format[] = { '%', '+', 'd', '\0' }; SNPRINTF (p, 6 + 1, decimal_format, exponent); } -# else +# else sprintf (p, "%+d", exponent); -# endif +# endif while (*p != '\0') p++; } @@ -577,7 +561,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar } } else -# endif { double arg = a.arg[dp->arg_index].a.a_double; @@ -596,22 +579,11 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar { int sign = 0; - if (arg < 0.0) + if (signbit (arg)) /* arg < 0.0 or negative zero */ { sign = -1; arg = -arg; } - else if (arg == 0.0) - { - /* Distinguish 0.0 and -0.0. */ - static double plus_zero = 0.0; - double arg_mem = arg; - if (memcmp (&plus_zero, &arg_mem, SIZEOF_DBL) != 0) - { - sign = -1; - arg = -arg; - } - } if (sign < 0) *p++ = '-'; @@ -932,7 +904,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar break; case 'f': case 'F': -# if HAVE_LONG_DOUBLE if (type == TYPE_LONGDOUBLE) tmp_length = (unsigned int) (LDBL_MAX_EXP @@ -942,7 +913,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar + 1 /* turn floor into ceil */ + 10; /* sign, decimal point etc. */ else -# endif tmp_length = (unsigned int) (DBL_MAX_EXP * 0.30103 /* binary -> decimal */ @@ -960,7 +930,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar break; case 'a': case 'A': -# if HAVE_LONG_DOUBLE if (type == TYPE_LONGDOUBLE) tmp_length = (unsigned int) (LDBL_DIG @@ -968,7 +937,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar ) + 1; /* turn floor into ceil */ else -# endif tmp_length = (unsigned int) (DBL_DIG * 0.831 /* decimal -> hexadecimal */ @@ -1087,15 +1055,18 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar #endif *p++ = 'l'; break; -#if HAVE_LONG_DOUBLE case TYPE_LONGDOUBLE: *p++ = 'L'; break; -#endif default: break; } - *p = dp->conversion; +#if NEED_PRINTF_DIRECTIVE_F + if (dp->conversion == 'F') + *p = 'f'; + else +#endif + *p = dp->conversion; #if USE_SNPRINTF p[1] = '%'; p[2] = 'n'; @@ -1248,14 +1219,12 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar SNPRINTF_BUF (arg); } break; -#if HAVE_LONG_DOUBLE case TYPE_LONGDOUBLE: { long double arg = a.arg[dp->arg_index].a.a_longdouble; SNPRINTF_BUF (arg); } break; -#endif case TYPE_CHAR: { int arg = a.arg[dp->arg_index].a.a_char; @@ -1384,6 +1353,18 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar free (tmp); #endif +#if NEED_PRINTF_DIRECTIVE_F + if (dp->conversion == 'F') + { + /* Convert the %f result to upper case for %F. */ + CHAR_T *rp = result + length; + size_t rc; + for (rc = count; rc > 0; rc--, rp++) + if (*rp >= 'a' && *rp <= 'z') + *rp = *rp - 'a' + 'A'; + } +#endif + length += count; break; } |