Commit a073116c authored by Bruno Haible's avatar Bruno Haible

Fix the processing of finite numbers with the 'a' and 'A' directives.

parent 118e62dd
2007-11-05 Bruno Haible <bruno@clisp.org>
* lib/vasnprintf.c (VASNPRINTF): Expand the NEED_PRINTF_DIRECTIVE_A
code when NEED_PRINTF_LONG_DOUBLE or NEED_PRINTF_DOUBLE is set.
Needed on Cygwin, where !NEED_PRINTF_DIRECTIVE_A && NEED_PRINTF_DOUBLE.
Reported by Eric Blake.
2007-10-27 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
Bruno Haible <bruno@clisp.org>
......@@ -104,10 +104,14 @@
# include "fpucw.h"
#endif
#if NEED_PRINTF_DIRECTIVE_A && !defined IN_LIBINTL
#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
# include <math.h>
# include "isnan.h"
# include "printf-frexp.h"
#endif
#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
# include <math.h>
# include "isnanl-nolibm.h"
# include "printf-frexpl.h"
# include "fpucw.h"
......@@ -2033,8 +2037,19 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
}
#endif
#if NEED_PRINTF_DIRECTIVE_A && !defined IN_LIBINTL
else if (dp->conversion == 'a' || dp->conversion == 'A')
#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
else if ((dp->conversion == 'a' || dp->conversion == 'A')
# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
&& (0
# if NEED_PRINTF_DOUBLE
|| a.arg[dp->arg_index].type == TYPE_DOUBLE
# endif
# if NEED_PRINTF_LONG_DOUBLE
|| a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
# endif
)
# endif
)
{
arg_type type = a.arg[dp->arg_index].type;
int flags = dp->flags;
......@@ -2152,6 +2167,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
p = tmp;
if (type == TYPE_LONGDOUBLE)
{
# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE
long double arg = a.arg[dp->arg_index].a.a_longdouble;
if (isnanl (arg))
......@@ -2271,7 +2287,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
}
*p++ = dp->conversion - 'A' + 'P';
# if WIDE_CHAR_VERSION
# if WIDE_CHAR_VERSION
{
static const wchar_t decimal_format[] =
{ '%', '+', 'd', '\0' };
......@@ -2279,7 +2295,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
while (*p != '\0')
p++;
# else
# else
if (sizeof (DCHAR_T) == 1)
{
sprintf ((char *) p, "%+d", exponent);
......@@ -2294,14 +2310,18 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
for (ep = expbuf; (*p = *ep) != '\0'; ep++)
p++;
}
# endif
# endif
}
END_LONG_DOUBLE_ROUNDING ();
}
# else
abort ();
# endif
}
else
{
# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE
double arg = a.arg[dp->arg_index].a.a_double;
if (isnan (arg))
......@@ -2418,7 +2438,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
}
*p++ = dp->conversion - 'A' + 'P';
# if WIDE_CHAR_VERSION
# if WIDE_CHAR_VERSION
{
static const wchar_t decimal_format[] =
{ '%', '+', 'd', '\0' };
......@@ -2426,7 +2446,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
while (*p != '\0')
p++;
# else
# else
if (sizeof (DCHAR_T) == 1)
{
sprintf ((char *) p, "%+d", exponent);
......@@ -2441,9 +2461,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
for (ep = expbuf; (*p = *ep) != '\0'; ep++)
p++;
}
# endif
# endif
}
}
# else
abort ();
# endif
}
/* The generated string now extends from tmp to p, with the
zero padding insertion point being at pad_ptr. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment