/* Test of POSIX compatible vsnprintf() and snprintf() functions.
- Copyright (C) 2007-2008 Free Software Foundation, Inc.
+ Copyright (C) 2007-2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
}
/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
- So we use -zero instead. */
+ So we use -zerod instead. */
double zerod = 0.0;
-/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0L.
- So we use -zero instead. */
-long double zerol = 0.0L;
+/* On HP-UX 10.20, negating 0.0L does not yield -0.0L.
+ So we use minus_zerol instead.
+ IRIX cc can't put -0.0L into .data, but can compute at runtime.
+ Note that the expression -LDBL_MIN * LDBL_MIN does not work on other
+ platforms, such as when cross-compiling to PowerPC on MacOS X 10.5. */
+#if defined __hpux || defined __sgi
+static long double
+compute_minus_zerol (void)
+{
+ return -LDBL_MIN * LDBL_MIN;
+}
+# define minus_zerol compute_minus_zerol ()
+#else
+long double minus_zerol = -0.0L;
+#endif
/* Representation of an 80-bit 'long double' as an initializer for a sequence
of 'unsigned int' words. */
{ /* Negative zero. */
char result[100];
int retval =
- my_snprintf (result, sizeof (result), "%La %d", -zerol, 33, 44, 55);
+ my_snprintf (result, sizeof (result), "%La %d", minus_zerol, 33, 44, 55);
if (have_minus_zero ())
ASSERT (strcmp (result, "-0x0p+0 33") == 0);
ASSERT (retval == strlen (result));
{ /* Negative zero. */
char result[100];
int retval =
- my_snprintf (result, sizeof (result), "%Lf %d", -zerol, 33, 44, 55);
+ my_snprintf (result, sizeof (result), "%Lf %d", minus_zerol, 33, 44, 55);
if (have_minus_zero ())
ASSERT (strcmp (result, "-0.000000 33") == 0);
ASSERT (retval == strlen (result));
{ /* Negative zero. */
char result[100];
int retval =
- my_snprintf (result, sizeof (result), "%LF %d", -zerol, 33, 44, 55);
+ my_snprintf (result, sizeof (result), "%LF %d", minus_zerol, 33, 44, 55);
if (have_minus_zero ())
ASSERT (strcmp (result, "-0.000000 33") == 0);
ASSERT (retval == strlen (result));
{ /* Negative zero. */
char result[100];
int retval =
- my_snprintf (result, sizeof (result), "%Le %d", -zerol, 33, 44, 55);
+ my_snprintf (result, sizeof (result), "%Le %d", minus_zerol, 33, 44, 55);
if (have_minus_zero ())
ASSERT (strcmp (result, "-0.000000e+00 33") == 0
|| strcmp (result, "-0.000000e+000 33") == 0);
{ /* Negative zero. */
char result[100];
int retval =
- my_snprintf (result, sizeof (result), "%Lg %d", -zerol, 33, 44, 55);
+ my_snprintf (result, sizeof (result), "%Lg %d", minus_zerol, 33, 44, 55);
if (have_minus_zero ())
ASSERT (strcmp (result, "-0 33") == 0);
ASSERT (retval == strlen (result));