The "right" way to test for -0 versus +0 is to use copysign.
For example, instead of this:
if (arg < 0.0L)
{
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;
}
}
vasnprintf.c should do this:
if (copysignl (1, arg) < 0)
{
sign = -1;
arg = -arg;
}
This is a valid transformation since we know at this point that ARG is
not a NaN.
I think it's much cleaner. And the code is smaller on my platform,
anyway: no function call is generated for copysignl. It should be
fast enough for vasnprintf.
This needs copysignl for older platforms, but another gnulib module
should suffice for that....