changeset 8860:771a56a41b5b

Fix *printf result for NaN, Inf on AIX, Solaris, OSF/1.
author Bruno Haible <bruno@clisp.org>
date Sun, 20 May 2007 09:01:48 +0000
parents 6d52d75c164e
children 814d6b735b16
files ChangeLog doc/functions/fprintf.texi doc/functions/printf.texi doc/functions/snprintf.texi doc/functions/sprintf.texi doc/functions/vfprintf.texi doc/functions/vprintf.texi doc/functions/vsnprintf.texi doc/functions/vsprintf.texi lib/vasnprintf.c m4/fprintf-posix.m4 m4/printf.m4 m4/snprintf-posix.m4 m4/sprintf-posix.m4 m4/vasnprintf-posix.m4 m4/vasnprintf.m4 m4/vasprintf-posix.m4 m4/vfprintf-posix.m4 m4/vsnprintf-posix.m4 m4/vsprintf-posix.m4
diffstat 20 files changed, 460 insertions(+), 233 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2007-05-20  Bruno Haible  <bruno@clisp.org>
+
+	Fix *printf result for NaN, Inf on AIX, Solaris, OSF/1.
+	* m4/printf.m4 (gl_PRINTF_INFINITE): Update cross-compiling guesses.
+	(gl_PRINTF_INFINITE_LONG_DOUBLE): New macro.
+	* lib/vasnprintf.c: Use NEED_PRINTF_INFINITE_DOUBLE instead of
+	NEED_PRINTF_INFINITE.
+	(is_infinitel): New function.
+	(VASNPRINTF): Handle NEED_PRINTF_INFINITE_LONG_DOUBLE case.
+	* m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE): Renamed from
+	gl_PREREQ_VASNPRINTF_INFINITE.
+	(gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE): New macro.
+	* m4/fprintf-posix.m4 (gl_FUNC_FPRINTF_POSIX): Invoke
+	gl_PRINTF_INFINITE_LONG_DOUBLE and test its result. Invoke
+	gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE and
+	gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE instead of
+	gl_PREREQ_VASNPRINTF_INFINITE.
+	* m4/snprintf-posix.m4 (gl_FUNC_SNPRINTF_POSIX): Likewise.
+	* m4/sprintf-posix.m4 (gl_FUNC_SPRINTF_POSIX): Likewise.
+	* m4/vasnprintf-posix.m4 (gl_FUNC_VASNPRINTF_POSIX): Likewise.
+	* m4/vasprintf-posix.m4 (gl_FUNC_VASPRINTF_POSIX): Likewise.
+	* m4/vfprintf-posix.m4 (gl_FUNC_VFPRINTF_POSIX): Likewise.
+	* m4/vsnprintf-posix.m4 (gl_FUNC_VSNPRINTF_POSIX): Likewise.
+	* m4/vsprintf-posix.m4 (gl_FUNC_VSPRINTF_POSIX): Likewise.
+	* doc/functions/fprintf.texi: Update.
+	* doc/functions/printf.texi: Update.
+	* doc/functions/snprintf.texi: Update.
+	* doc/functions/sprintf.texi: Update.
+	* doc/functions/vfprintf.texi: Update.
+	* doc/functions/vprintf.texi: Update.
+	* doc/functions/vsnprintf.texi: Update.
+	* doc/functions/vsprintf.texi: Update.
+
 2007-05-20  Bruno Haible  <bruno@clisp.org>
 
 	* m4/frexpl.m4 (gl_FUNC_FREXPL_NO_LIBM): Set REPLACE_FREXPL if frexpl
--- a/doc/functions/fprintf.texi
+++ b/doc/functions/fprintf.texi
@@ -13,12 +13,12 @@
 @code{j}, @code{t}, @code{z}) on some platforms:
 AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 2006, mingw, BeOS.
 @item
+printf of @samp{long double} numbers is unsupported on some platforms:
+mingw, BeOS.
+@item
 printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
-mingw.
-@item
-printf of @samp{long double} numbers is unsupported on some platforms:
-mingw, BeOS.
+AIX 5.2, OSF/1 5.1, Solaris 10, mingw.
 @item
 This function does not support the @samp{a} and @samp{A} directives on some
 platforms:
--- a/doc/functions/printf.texi
+++ b/doc/functions/printf.texi
@@ -13,12 +13,12 @@
 @code{j}, @code{t}, @code{z}) on some platforms:
 AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 2006, mingw, BeOS.
 @item
+printf of @samp{long double} numbers is unsupported on some platforms:
+mingw, BeOS.
+@item
 printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
-mingw.
-@item
-printf of @samp{long double} numbers is unsupported on some platforms:
-mingw, BeOS.
+AIX 5.2, OSF/1 5.1, Solaris 10, mingw.
 @item
 This function does not support the @samp{a} and @samp{A} directives on some
 platforms:
--- a/doc/functions/snprintf.texi
+++ b/doc/functions/snprintf.texi
@@ -20,12 +20,12 @@
 @code{j}, @code{t}, @code{z}) on some platforms:
 AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 2006, mingw, BeOS.
 @item
+printf of @samp{long double} numbers is unsupported on some platforms:
+mingw, BeOS.
+@item
 printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
-mingw.
-@item
-printf of @samp{long double} numbers is unsupported on some platforms:
-mingw, BeOS.
+AIX 5.2, OSF/1 5.1, Solaris 10, mingw.
 @item
 This function does not support the @samp{a} and @samp{A} directives on some
 platforms:
--- a/doc/functions/sprintf.texi
+++ b/doc/functions/sprintf.texi
@@ -13,12 +13,12 @@
 @code{j}, @code{t}, @code{z}) on some platforms:
 AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 2006, mingw, BeOS.
 @item
+printf of @samp{long double} numbers is unsupported on some platforms:
+mingw, BeOS.
+@item
 printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
-mingw.
-@item
-printf of @samp{long double} numbers is unsupported on some platforms:
-mingw, BeOS.
+AIX 5.2, OSF/1 5.1, Solaris 10, mingw.
 @item
 This function does not support the @samp{a} and @samp{A} directives on some
 platforms:
--- a/doc/functions/vfprintf.texi
+++ b/doc/functions/vfprintf.texi
@@ -13,12 +13,12 @@
 @code{j}, @code{t}, @code{z}) on some platforms:
 AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 2006, mingw, BeOS.
 @item
+printf of @samp{long double} numbers is unsupported on some platforms:
+mingw, BeOS.
+@item
 printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
-mingw.
-@item
-printf of @samp{long double} numbers is unsupported on some platforms:
-mingw, BeOS.
+AIX 5.2, OSF/1 5.1, Solaris 10, mingw.
 @item
 This function does not support the @samp{a} and @samp{A} directives on some
 platforms:
--- a/doc/functions/vprintf.texi
+++ b/doc/functions/vprintf.texi
@@ -13,12 +13,12 @@
 @code{j}, @code{t}, @code{z}) on some platforms:
 AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 2006, mingw, BeOS.
 @item
+printf of @samp{long double} numbers is unsupported on some platforms:
+mingw, BeOS.
+@item
 printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
-mingw.
-@item
-printf of @samp{long double} numbers is unsupported on some platforms:
-mingw, BeOS.
+AIX 5.2, OSF/1 5.1, Solaris 10, mingw.
 @item
 This function does not support the @samp{a} and @samp{A} directives on some
 platforms:
--- a/doc/functions/vsnprintf.texi
+++ b/doc/functions/vsnprintf.texi
@@ -20,12 +20,12 @@
 @code{j}, @code{t}, @code{z}) on some platforms:
 AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 2006, mingw, BeOS.
 @item
+printf of @samp{long double} numbers is unsupported on some platforms:
+mingw, BeOS.
+@item
 printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
-mingw.
-@item
-printf of @samp{long double} numbers is unsupported on some platforms:
-mingw, BeOS.
+AIX 5.2, OSF/1 5.1, Solaris 10, mingw.
 @item
 This function does not support the @samp{a} and @samp{A} directives on some
 platforms:
--- a/doc/functions/vsprintf.texi
+++ b/doc/functions/vsprintf.texi
@@ -13,12 +13,12 @@
 @code{j}, @code{t}, @code{z}) on some platforms:
 AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 2006, mingw, BeOS.
 @item
+printf of @samp{long double} numbers is unsupported on some platforms:
+mingw, BeOS.
+@item
 printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
-mingw.
-@item
-printf of @samp{long double} numbers is unsupported on some platforms:
-mingw, BeOS.
+AIX 5.2, OSF/1 5.1, Solaris 10, mingw.
 @item
 This function does not support the @samp{a} and @samp{A} directives on some
 platforms:
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -53,14 +53,19 @@
 /* Checked size_t computations.  */
 #include "xsize.h"
 
-#if NEED_PRINTF_INFINITE && !defined IN_LIBINTL
+#if NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL
+# include <math.h>
+# include "float+.h"
+#endif
+
+#if NEED_PRINTF_INFINITE_DOUBLE && !defined IN_LIBINTL
 # include <math.h>
 # include "isnan.h"
 #endif
 
-#if NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL
+#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !defined IN_LIBINTL
 # include <math.h>
-# include "float+.h"
+# include "isnanl-nolibm.h"
 #endif
 
 #if NEED_PRINTF_DIRECTIVE_A && !defined IN_LIBINTL
@@ -169,7 +174,7 @@
 # endif
 #endif
 
-#if NEED_PRINTF_INFINITE && !defined IN_LIBINTL
+#if NEED_PRINTF_INFINITE_DOUBLE && !defined IN_LIBINTL
 
 /* Equivalent to !isfinite(x) || x == 0, but does not require libm.  */
 static int
@@ -180,6 +185,17 @@
 
 #endif
 
+#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !defined IN_LIBINTL
+
+/* Equivalent to !isfinite(x), but does not require libm.  */
+static int
+is_infinitel (long double x)
+{
+  return isnanl (x) || (x + x == x && x != 0.0L);
+}
+
+#endif
+
 #if NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL
 
 /* Converting 'long double' to decimal without rare rounding bugs requires
@@ -1273,12 +1289,12 @@
 		    abort ();
 		  }
 	      }
-#if (NEED_PRINTF_INFINITE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
+#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
 	    else if ((dp->conversion == 'f' || dp->conversion == 'F'
 		      || dp->conversion == 'e' || dp->conversion == 'E'
 		      || dp->conversion == 'g' || dp->conversion == 'G')
 		     && (0
-# if NEED_PRINTF_INFINITE
+# if NEED_PRINTF_INFINITE_DOUBLE
 			 || (a.arg[dp->arg_index].type == TYPE_DOUBLE
 			     /* The systems (mingw) which produce wrong output
 				for Inf and -Inf also do so for NaN and -0.0.
@@ -1287,10 +1303,16 @@
 # endif
 # if NEED_PRINTF_LONG_DOUBLE
 			 || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
+# elif NEED_PRINTF_INFINITE_LONG_DOUBLE
+			 || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
+			     /* The systems which produce wrong output for Inf
+				and -Inf also do so for NaN.  Therefore treat
+				this case here as well.  */
+			     && is_infinitel (a.arg[dp->arg_index].a.a_longdouble))
 # endif
 			))
 	      {
-# if NEED_PRINTF_INFINITE && NEED_PRINTF_LONG_DOUBLE
+# if NEED_PRINTF_INFINITE_DOUBLE && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE)
 		arg_type type = a.arg[dp->arg_index].type;
 # endif
 		int flags = dp->flags;
@@ -1373,17 +1395,17 @@
 		  precision = 6;
 
 		/* Allocate a temporary buffer of sufficient size.  */
-# if NEED_PRINTF_INFINITE && NEED_PRINTF_LONG_DOUBLE
+# if NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE
 		tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0);
 # elif NEED_PRINTF_LONG_DOUBLE
 		tmp_length = LDBL_DIG + 1;
-# elif NEED_PRINTF_INFINITE
+# else
 		tmp_length = 0;
 # endif
 		if (tmp_length < precision)
 		  tmp_length = precision;
 # if NEED_PRINTF_LONG_DOUBLE
-#  if NEED_PRINTF_INFINITE
+#  if NEED_PRINTF_INFINITE_DOUBLE
 		if (type == TYPE_LONGDOUBLE)
 #  endif
 		  if (dp->conversion == 'f' || dp->conversion == 'F')
@@ -1424,8 +1446,8 @@
 		pad_ptr = NULL;
 		p = tmp;
 
-# if NEED_PRINTF_LONG_DOUBLE
-#  if NEED_PRINTF_INFINITE
+# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
+#  if NEED_PRINTF_INFINITE_DOUBLE
 		if (type == TYPE_LONGDOUBLE)
 #  endif
 		  {
@@ -1475,6 +1497,7 @@
 			  }
 			else
 			  {
+#  if NEED_PRINTF_LONG_DOUBLE
 			    pad_ptr = p;
 
 			    if (dp->conversion == 'f' || dp->conversion == 'F')
@@ -1587,15 +1610,15 @@
 				  }
 
 				*p++ = dp->conversion; /* 'e' or 'E' */
-#  if WIDE_CHAR_VERSION
+#   if WIDE_CHAR_VERSION
 				{
 				  static const wchar_t decimal_format[] =
 				    { '%', '+', '.', '2', 'd', '\0' };
 				  SNPRINTF (p, 6 + 1, decimal_format, exponent);
 				}
-#  else
+#   else
 				sprintf (p, "%+.2d", exponent);
-#  endif
+#   endif
 				while (*p != '\0')
 				  p++;
 			      }
@@ -1731,15 +1754,15 @@
 					      }
 					  }
 					*p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */
-#  if WIDE_CHAR_VERSION
+#   if WIDE_CHAR_VERSION
 					{
 					  static const wchar_t decimal_format[] =
 					    { '%', '+', '.', '2', 'd', '\0' };
 					  SNPRINTF (p, 6 + 1, decimal_format, exponent);
 					}
-#  else
+#   else
 					sprintf (p, "%+.2d", exponent);
-#  endif
+#   endif
 					while (*p != '\0')
 					  p++;
 				      }
@@ -1749,16 +1772,20 @@
 			      }
 			    else
 			      abort ();
+#  else
+			    /* arg is finite.  */
+			    abort ();
+#  endif
 			  }
 
 			END_LONG_DOUBLE_ROUNDING ();
 		      }
 		  }
-#  if NEED_PRINTF_INFINITE
+#  if NEED_PRINTF_INFINITE_DOUBLE
 		else
 #  endif
 # endif
-# if NEED_PRINTF_INFINITE
+# if NEED_PRINTF_INFINITE_DOUBLE
 		  {
 		    /* Simpler than above: handle only NaN, Infinity, zero.  */
 		    double arg = a.arg[dp->arg_index].a.a_double;
@@ -1832,9 +1859,9 @@
 				*p++ = '+';
 				/* Produce the same number of exponent digits as
 				   the native printf implementation.  */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#  if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 				*p++ = '0';
-# endif
+#  endif
 				*p++ = '0';
 				*p++ = '0';
 			      }
--- a/m4/fprintf-posix.m4
+++ b/m4/fprintf-posix.m4
@@ -8,8 +8,9 @@
 [
   AC_REQUIRE([gl_EOVERFLOW])
   AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_INFINITE])
-  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
+  AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
@@ -19,25 +20,29 @@
   gl_cv_func_fprintf_posix=no
   case "$gl_cv_func_printf_sizes_c99" in
     *yes)
-      case "$gl_cv_func_printf_infinite" in
+      case "$gl_cv_func_printf_long_double" in
         *yes)
-          case "$gl_cv_func_printf_long_double" in
+          case "$gl_cv_func_printf_infinite" in
             *yes)
-              case "$gl_cv_func_printf_directive_a" in
+              case "$gl_cv_func_printf_infinite_long_double" in
                 *yes)
-                  case "$gl_cv_func_printf_directive_f" in
+                  case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_n" in
+                      case "$gl_cv_func_printf_directive_f" in
                         *yes)
-                          case "$gl_cv_func_printf_positions" in
+                          case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_flag_grouping" in
+                              case "$gl_cv_func_printf_positions" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_zero" in
+                                  case "$gl_cv_func_printf_flag_grouping" in
                                     *yes)
-                                      # fprintf exists and is already POSIX
-                                      # compliant.
-                                      gl_cv_func_fprintf_posix=yes
+                                      case "$gl_cv_func_printf_flag_zero" in
+                                        *yes)
+                                          # fprintf exists and is already POSIX
+                                          # compliant.
+                                          gl_cv_func_fprintf_posix=yes
+                                          ;;
+                                      esac
                                       ;;
                                   esac
                                   ;;
@@ -57,8 +62,9 @@
       ;;
   esac
   if test $gl_cv_func_fprintf_posix = no; then
-    gl_PREREQ_VASNPRINTF_INFINITE
     gl_PREREQ_VASNPRINTF_LONG_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
     gl_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_PREREQ_VASNPRINTF_DIRECTIVE_F
     gl_PREREQ_VASNPRINTF_FLAG_GROUPING
--- a/m4/printf.m4
+++ b/m4/printf.m4
@@ -1,4 +1,4 @@
-# printf.m4 serial 11
+# printf.m4 serial 12
 dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -164,14 +164,108 @@
       [
 changequote(,)dnl
        case "$host_os" in
-         mingw* | pw*) gl_cv_func_printf_infinite="guessing no";;
-         *)            gl_cv_func_printf_infinite="guessing yes";;
+                               # Guess yes on glibc systems.
+         *-gnu*)               gl_cv_func_printf_infinite="guessing yes";;
+                               # Guess yes on FreeBSD >= 6.
+         freebsd[1-5]*)        gl_cv_func_printf_infinite="guessing no";;
+         freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
+                               # Guess yes on MacOS X >= 10.3.
+         darwin[1-6].*)        gl_cv_func_printf_infinite="guessing no";;
+         darwin*)              gl_cv_func_printf_infinite="guessing yes";;
+                               # Guess yes on HP-UX >= 11.
+         hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
+         hpux*)                gl_cv_func_printf_infinite="guessing yes";;
+                               # Guess yes on IRIX >= 6.5.
+         irix6.5)              gl_cv_func_printf_infinite="guessing yes";;
+                               # Guess yes on NetBSD >= 3.
+         netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
+                               gl_cv_func_printf_infinite="guessing no";;
+         netbsd*)              gl_cv_func_printf_infinite="guessing yes";;
+                               # Guess yes on BeOS.
+         beos*)                gl_cv_func_printf_infinite="guessing yes";;
+                               # If we don't know, assume the worst.
+         *)                    gl_cv_func_printf_infinite="guessing no";;
        esac
 changequote([,])dnl
       ])
     ])
 ])
 
+dnl Test whether the *printf family of functions supports infinite 'long double'
+dnl arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
+dnl Result is gl_cv_func_printf_infinite_long_double.
+
+AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
+[
+  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  case "$gl_cv_func_printf_long_double" in
+    *yes)
+      AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
+        [gl_cv_func_printf_infinite_long_double],
+        [
+          AC_TRY_RUN([
+#include <stdio.h>
+#include <string.h>
+static char buf[100];
+int main ()
+{
+  if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0
+      || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
+    return 1;
+  if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0
+      || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
+    return 1;
+  if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0
+      || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
+    return 1;
+  if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0
+      || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
+    return 1;
+  if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0
+      || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
+    return 1;
+  if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0
+      || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
+    return 1;
+  return 0;
+}],
+          [gl_cv_func_printf_infinite_long_double=yes],
+          [gl_cv_func_printf_infinite_long_double=no],
+          [
+changequote(,)dnl
+           case "$host_os" in
+                                   # Guess yes on glibc systems.
+             *-gnu*)               gl_cv_func_printf_infinite_long_double="guessing yes";;
+                                   # Guess yes on FreeBSD >= 6.
+             freebsd[1-5]*)        gl_cv_func_printf_infinite_long_double="guessing no";;
+             freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
+                                   # Guess yes on MacOS X >= 10.3.
+             darwin[1-6].*)        gl_cv_func_printf_infinite_long_double="guessing no";;
+             darwin*)              gl_cv_func_printf_infinite_long_double="guessing yes";;
+                                   # Guess yes on HP-UX >= 11.
+             hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
+             hpux*)                gl_cv_func_printf_infinite_long_double="guessing yes";;
+                                   # Guess yes on IRIX >= 6.5.
+             irix6.5)              gl_cv_func_printf_infinite_long_double="guessing yes";;
+                                   # Guess yes on NetBSD >= 3.
+             netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
+                                   gl_cv_func_printf_infinite_long_double="guessing no";;
+             netbsd*)              gl_cv_func_printf_infinite_long_double="guessing yes";;
+                                   # If we don't know, assume the worst.
+             *)                    gl_cv_func_printf_infinite_long_double="guessing no";;
+           esac
+changequote([,])dnl
+          ])
+        ])
+      ;;
+    *)
+      gl_cv_func_printf_infinite_long_double="irrelevant"
+      ;;
+  esac
+])
+
 dnl Test whether the *printf family of functions supports the 'a' and 'A'
 dnl conversion specifier for hexadecimal output of floating-point numbers.
 dnl (ISO C99, POSIX:2001)
@@ -755,54 +849,56 @@
 dnl 1 = gl_PRINTF_SIZES_C99
 dnl 2 = gl_PRINTF_LONG_DOUBLE
 dnl 3 = gl_PRINTF_INFINITE
-dnl 4 = gl_PRINTF_DIRECTIVE_A
-dnl 5 = gl_PRINTF_DIRECTIVE_F
-dnl 6 = gl_PRINTF_DIRECTIVE_N
-dnl 7 = gl_PRINTF_POSITIONS
-dnl 8 = gl_PRINTF_FLAG_GROUPING
-dnl 9 = gl_PRINTF_FLAG_ZERO
-dnl 10 = gl_SNPRINTF_PRESENCE
-dnl 11 = gl_SNPRINTF_TRUNCATION_C99
-dnl 12 = gl_SNPRINTF_RETVAL_C99
-dnl 13 = gl_SNPRINTF_DIRECTIVE_N
-dnl 14 = gl_VSNPRINTF_ZEROSIZE_C99
+dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
+dnl 5 = gl_PRINTF_DIRECTIVE_A
+dnl 6 = gl_PRINTF_DIRECTIVE_F
+dnl 7 = gl_PRINTF_DIRECTIVE_N
+dnl 8 = gl_PRINTF_POSITIONS
+dnl 9 = gl_PRINTF_FLAG_GROUPING
+dnl 10 = gl_PRINTF_FLAG_ZERO
+dnl 11 = gl_SNPRINTF_PRESENCE
+dnl 12 = gl_SNPRINTF_TRUNCATION_C99
+dnl 13 = gl_SNPRINTF_RETVAL_C99
+dnl 14 = gl_SNPRINTF_DIRECTIVE_N
+dnl 15 = gl_VSNPRINTF_ZEROSIZE_C99
 dnl
 dnl 1 = checking whether printf supports size specifiers as in C99...
 dnl 2 = checking whether printf supports 'long double' arguments...
 dnl 3 = checking whether printf supports infinite 'double' arguments...
-dnl 4 = checking whether printf supports the 'a' and 'A' directives...
-dnl 5 = checking whether printf supports the 'F' directive...
-dnl 6 = checking whether printf supports the 'n' directive...
-dnl 7 = checking whether printf supports POSIX/XSI format strings with positions...
-dnl 8 = checking whether printf supports the grouping flag...
-dnl 9 = checking whether printf supports the zero flag correctly...
-dnl 10 = checking for snprintf...
-dnl 11 = checking whether snprintf truncates the result as in C99...
-dnl 12 = checking whether snprintf returns a byte count as in C99...
-dnl 13 = checking whether snprintf fully supports the 'n' directive...
-dnl 14 = checking whether vsnprintf respects a zero size as in C99...
+dnl 4 = checking whether printf supports infinite 'long double' arguments...
+dnl 5 = checking whether printf supports the 'a' and 'A' directives...
+dnl 6 = checking whether printf supports the 'F' directive...
+dnl 7 = checking whether printf supports the 'n' directive...
+dnl 8 = checking whether printf supports POSIX/XSI format strings with positions...
+dnl 9 = checking whether printf supports the grouping flag...
+dnl 10 = checking whether printf supports the zero flag correctly...
+dnl 11 = checking for snprintf...
+dnl 12 = checking whether snprintf truncates the result as in C99...
+dnl 13 = checking whether snprintf returns a byte count as in C99...
+dnl 14 = checking whether snprintf fully supports the 'n' directive...
+dnl 15 = checking whether vsnprintf respects a zero size as in C99...
 dnl
 dnl . = yes, # = no.
 dnl
-dnl                                     1  2  3  4  5  6  7  8  9 10 11 12 13 14
-dnl   glibc 2.5                         .  .  .  .  .  .  .  .  .  .  .  .  .  .
-dnl   glibc 2.3.6                       .  .  .  #  .  .  .  .  .  .  .  .  .  .
-dnl   FreeBSD 5.4, 6.1                  .  ?  .  ?  .  .  .  .  #  .  .  .  .  .
-dnl   MacOS X 10.3.9                    .  .  .  #  .  .  .  .  #  .  .  .  .  .
-dnl   OpenBSD 3.9, 4.0                  .  ?  ?  #  ?  .  .  ?  ?  .  .  .  ?  ?
-dnl   Cygwin 2007 (= Cygwin 1.5.24)     .  ?  ?  #  #  .  .  .  #  .  .  .  .  .
-dnl   Cygwin 2006 (= Cygwin 1.5.19)     #  ?  ?  #  #  .  .  #  #  .  .  .  .  .
-dnl   Solaris 10                        .  .  ?  #  .  .  .  .  #  .  .  .  .  .
-dnl   Solaris 2.6 ... 9                 #  .  ?  #  #  .  .  .  #  .  .  .  .  .
-dnl   Solaris 2.5.1                     #  .  #  #  #  .  .  .  #  #  #  #  #  #
-dnl   AIX 5.2                           .  .  ?  #  .  .  .  .  #  .  .  .  .  .
-dnl   AIX 4.3.2, 5.1                    #  .  #  #  #  .  .  .  #  .  .  .  .  .
-dnl   HP-UX 11.31                       .  .  .  #  .  .  .  .  #  .  .  #  #  .
-dnl   HP-UX 10.20, 11.{00,11,23}        #  .  .  #  #  .  .  .  #  .  .  #  #  #
-dnl   IRIX 6.5                          #  .  .  #  #  .  .  .  #  .  .  #  .  .
-dnl   OSF/1 5.1                         #  .  ?  #  #  .  .  .  #  .  .  #  .  #
-dnl   OSF/1 4.0d                        #  .  #  #  #  .  .  .  #  #  #  #  #  #
-dnl   NetBSD 4.0                        .  ?  ?  ?  ?  .  .  ?  ?  .  .  .  ?  ?
-dnl   NetBSD 3.0                        .  ?  ?  #  #  .  #  #  #  .  .  .  .  .
-dnl   BeOS                              #  #  ?  #  #  .  #  .  .  .  .  .  .  .
-dnl   mingw                             #  #  #  #  #  .  #  #  #  .  #  #  #  .
+dnl                                  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
+dnl   glibc 2.5                      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
+dnl   glibc 2.3.6                    .  .  .  .  #  .  .  .  .  .  .  .  .  .  .
+dnl   FreeBSD 5.4, 6.1               .  .  .  .  #  .  .  .  .  #  .  .  .  .  .
+dnl   MacOS X 10.3.9                 .  .  .  .  #  .  .  .  .  #  .  .  .  .  .
+dnl   OpenBSD 3.9, 4.0               .  ?  ?  ?  #  ?  .  .  ?  ?  .  .  .  ?  ?
+dnl   Cygwin 2007 (= Cygwin 1.5.24)  .  ?  ?  ?  #  #  .  .  .  #  .  .  .  .  .
+dnl   Cygwin 2006 (= Cygwin 1.5.19)  #  ?  ?  ?  #  #  .  .  #  #  .  .  .  .  .
+dnl   Solaris 10                     .  .  #  #  #  .  .  .  .  #  .  .  .  .  .
+dnl   Solaris 2.6 ... 9              #  .  #  #  #  #  .  .  .  #  .  .  .  .  .
+dnl   Solaris 2.5.1                  #  .  #  #  #  #  .  .  .  #  #  #  #  #  #
+dnl   AIX 5.2                        .  .  #  #  #  .  .  .  .  #  .  .  .  .  .
+dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  #  .  .  .  .  .
+dnl   HP-UX 11.31                    .  .  .  .  #  .  .  .  .  #  .  .  #  #  .
+dnl   HP-UX 10.20, 11.{00,11,23}     #  .  .  .  #  #  .  .  .  #  .  .  #  #  #
+dnl   IRIX 6.5                       #  .  .  .  #  #  .  .  .  #  .  .  #  .  .
+dnl   OSF/1 5.1                      #  .  #  #  #  #  .  .  .  #  .  .  #  .  #
+dnl   OSF/1 4.0d                     #  .  #  #  #  #  .  .  .  #  #  #  #  #  #
+dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  .  ?  ?  .  .  .  ?  ?
+dnl   NetBSD 3.0                     .  .  .  .  #  #  .  #  #  #  .  .  .  .  .
+dnl   BeOS                           #  #  .  #  #  #  .  #  .  .  .  .  .  .  .
+dnl   mingw                          #  #  #  #  #  #  .  #  #  #  .  #  #  #  .
--- a/m4/snprintf-posix.m4
+++ b/m4/snprintf-posix.m4
@@ -8,8 +8,9 @@
 [
   AC_REQUIRE([gl_EOVERFLOW])
   AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_INFINITE])
-  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
+  AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
@@ -25,33 +26,37 @@
     gl_VSNPRINTF_ZEROSIZE_C99
     case "$gl_cv_func_printf_sizes_c99" in
       *yes)
-        case "$gl_cv_func_printf_infinite" in
+        case "$gl_cv_func_printf_long_double" in
           *yes)
-            case "$gl_cv_func_printf_long_double" in
+            case "$gl_cv_func_printf_infinite" in
               *yes)
-                case "$gl_cv_func_printf_directive_a" in
+                case "$gl_cv_func_printf_infinite_long_double" in
                   *yes)
-                    case "$gl_cv_func_printf_directive_f" in
+                    case "$gl_cv_func_printf_directive_a" in
                       *yes)
-                        case "$gl_cv_func_printf_directive_n" in
+                        case "$gl_cv_func_printf_directive_f" in
                           *yes)
-                            case "$gl_cv_func_printf_positions" in
+                            case "$gl_cv_func_printf_directive_n" in
                               *yes)
-                                case "$gl_cv_func_printf_flag_grouping" in
+                                case "$gl_cv_func_printf_positions" in
                                   *yes)
-                                    case "$gl_cv_func_printf_flag_zero" in
+                                    case "$gl_cv_func_printf_flag_grouping" in
                                       *yes)
-                                        case "$gl_cv_func_snprintf_truncation_c99" in
+                                        case "$gl_cv_func_printf_flag_zero" in
                                           *yes)
-                                            case "$gl_cv_func_snprintf_retval_c99" in
+                                            case "$gl_cv_func_snprintf_truncation_c99" in
                                               *yes)
-                                                case "$gl_cv_func_snprintf_directive_n" in
+                                                case "$gl_cv_func_snprintf_retval_c99" in
                                                   *yes)
-                                                    case "$gl_cv_func_vsnprintf_zerosize_c99" in
+                                                    case "$gl_cv_func_snprintf_directive_n" in
                                                       *yes)
-                                                        # snprintf exists and is
-                                                        # already POSIX compliant.
-                                                        gl_cv_func_snprintf_posix=yes
+                                                        case "$gl_cv_func_vsnprintf_zerosize_c99" in
+                                                          *yes)
+                                                            # snprintf exists and is
+                                                            # already POSIX compliant.
+                                                            gl_cv_func_snprintf_posix=yes
+                                                            ;;
+                                                        esac
                                                         ;;
                                                     esac
                                                     ;;
@@ -80,8 +85,9 @@
     esac
   fi
   if test $gl_cv_func_snprintf_posix = no; then
-    gl_PREREQ_VASNPRINTF_INFINITE
     gl_PREREQ_VASNPRINTF_LONG_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
     gl_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_PREREQ_VASNPRINTF_DIRECTIVE_F
     gl_PREREQ_VASNPRINTF_FLAG_GROUPING
--- a/m4/sprintf-posix.m4
+++ b/m4/sprintf-posix.m4
@@ -8,8 +8,9 @@
 [
   AC_REQUIRE([gl_EOVERFLOW])
   AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_INFINITE])
-  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
+  AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
@@ -19,25 +20,29 @@
   gl_cv_func_sprintf_posix=no
   case "$gl_cv_func_printf_sizes_c99" in
     *yes)
-      case "$gl_cv_func_printf_infinite" in
+      case "$gl_cv_func_printf_long_double" in
         *yes)
-          case "$gl_cv_func_printf_long_double" in
+          case "$gl_cv_func_printf_infinite" in
             *yes)
-              case "$gl_cv_func_printf_directive_a" in
+              case "$gl_cv_func_printf_infinite_long_double" in
                 *yes)
-                  case "$gl_cv_func_printf_directive_f" in
+                  case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_n" in
+                      case "$gl_cv_func_printf_directive_f" in
                         *yes)
-                          case "$gl_cv_func_printf_positions" in
+                          case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_flag_grouping" in
+                              case "$gl_cv_func_printf_positions" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_zero" in
+                                  case "$gl_cv_func_printf_flag_grouping" in
                                     *yes)
-                                      # sprintf exists and is already POSIX
-                                      # compliant.
-                                      gl_cv_func_sprintf_posix=yes
+                                      case "$gl_cv_func_printf_flag_zero" in
+                                        *yes)
+                                          # sprintf exists and is already POSIX
+                                          # compliant.
+                                          gl_cv_func_sprintf_posix=yes
+                                          ;;
+                                      esac
                                       ;;
                                   esac
                                   ;;
@@ -57,8 +62,9 @@
       ;;
   esac
   if test $gl_cv_func_sprintf_posix = no; then
-    gl_PREREQ_VASNPRINTF_INFINITE
     gl_PREREQ_VASNPRINTF_LONG_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
     gl_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_PREREQ_VASNPRINTF_DIRECTIVE_F
     gl_PREREQ_VASNPRINTF_FLAG_GROUPING
--- a/m4/vasnprintf-posix.m4
+++ b/m4/vasnprintf-posix.m4
@@ -8,8 +8,9 @@
 [
   AC_REQUIRE([gl_EOVERFLOW])
   AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_INFINITE])
-  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
+  AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
@@ -20,27 +21,31 @@
   AC_CHECK_FUNCS_ONCE([vasnprintf])
   case "$gl_cv_func_printf_sizes_c99" in
     *yes)
-      case "$gl_cv_func_printf_infinite" in
+      case "$gl_cv_func_printf_long_double" in
         *yes)
-          case "$gl_cv_func_printf_long_double" in
+          case "$gl_cv_func_printf_infinite" in
             *yes)
-              case "$gl_cv_func_printf_directive_a" in
+              case "$gl_cv_func_printf_infinite_long_double" in
                 *yes)
-                  case "$gl_cv_func_printf_directive_f" in
+                  case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_n" in
+                      case "$gl_cv_func_printf_directive_f" in
                         *yes)
-                          case "$gl_cv_func_printf_positions" in
+                          case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_flag_grouping" in
+                              case "$gl_cv_func_printf_positions" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_zero" in
+                                  case "$gl_cv_func_printf_flag_grouping" in
                                     *yes)
-                                      if test $ac_cv_func_vasnprintf = yes; then
-                                        # vasnprintf exists and is already POSIX
-                                        # compliant.
-                                        gl_cv_func_vasnprintf_posix=yes
-                                      fi
+                                      case "$gl_cv_func_printf_flag_zero" in
+                                        *yes)
+                                          if test $ac_cv_func_vasnprintf = yes; then
+                                            # vasnprintf exists and is already
+                                            # POSIX compliant.
+                                            gl_cv_func_vasnprintf_posix=yes
+                                          fi
+                                          ;;
+                                      esac
                                       ;;
                                   esac
                                   ;;
@@ -60,8 +65,9 @@
       ;;
   esac
   if test $gl_cv_func_vasnprintf_posix = no; then
-    gl_PREREQ_VASNPRINTF_INFINITE
     gl_PREREQ_VASNPRINTF_LONG_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
     gl_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_PREREQ_VASNPRINTF_DIRECTIVE_F
     gl_PREREQ_VASNPRINTF_FLAG_GROUPING
--- a/m4/vasnprintf.m4
+++ b/m4/vasnprintf.m4
@@ -59,22 +59,6 @@
   AC_CHECK_FUNCS(snprintf wcslen)
 ])
 
-# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'double'
-# arguments.
-AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE],
-[
-  AC_REQUIRE([gl_PRINTF_INFINITE])
-  case "$gl_cv_func_printf_infinite" in
-    *yes)
-      ;;
-    *)
-      AC_DEFINE([NEED_PRINTF_INFINITE], 1,
-        [Define if the vasnprintf implementation needs special code for
-         infinite 'double' arguments.])
-      ;;
-  esac
-])
-
 # Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
 # arguments.
 AC_DEFUN([gl_PREREQ_VASNPRINTF_LONG_DOUBLE],
@@ -91,6 +75,45 @@
   esac
 ])
 
+# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'double'
+# arguments.
+AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE],
+[
+  AC_REQUIRE([gl_PRINTF_INFINITE])
+  case "$gl_cv_func_printf_infinite" in
+    *yes)
+      ;;
+    *)
+      AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], 1,
+        [Define if the vasnprintf implementation needs special code for
+         infinite 'double' arguments.])
+      ;;
+  esac
+])
+
+# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'long double'
+# arguments.
+AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE],
+[
+  AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
+  dnl There is no need to set NEED_PRINTF_INFINITE_LONG_DOUBLE if
+  dnl NEED_PRINTF_LONG_DOUBLE is already set.
+  AC_REQUIRE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE])
+  case "$gl_cv_func_printf_long_double" in
+    *yes)
+      case "$gl_cv_func_printf_infinite" in
+        *yes)
+          ;;
+        *)
+          AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], 1,
+            [Define if the vasnprintf implementation needs special code for
+             infinite 'long double' arguments.])
+          ;;
+      esac
+      ;;
+  esac
+])
+
 # Extra prerequisites of lib/vasnprintf.c for supporting the 'a' directive.
 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A],
 [
--- a/m4/vasprintf-posix.m4
+++ b/m4/vasprintf-posix.m4
@@ -8,8 +8,9 @@
 [
   AC_REQUIRE([gl_EOVERFLOW])
   AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_INFINITE])
-  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
+  AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
@@ -20,27 +21,31 @@
   AC_CHECK_FUNCS([vasprintf])
   case "$gl_cv_func_printf_sizes_c99" in
     *yes)
-      case "$gl_cv_func_printf_infinite" in
+      case "$gl_cv_func_printf_long_double" in
         *yes)
-          case "$gl_cv_func_printf_long_double" in
+          case "$gl_cv_func_printf_infinite" in
             *yes)
-              case "$gl_cv_func_printf_directive_a" in
+              case "$gl_cv_func_printf_infinite_long_double" in
                 *yes)
-                  case "$gl_cv_func_printf_directive_f" in
+                  case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_n" in
+                      case "$gl_cv_func_printf_directive_f" in
                         *yes)
-                          case "$gl_cv_func_printf_positions" in
+                          case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_flag_grouping" in
+                              case "$gl_cv_func_printf_positions" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_zero" in
+                                  case "$gl_cv_func_printf_flag_grouping" in
                                     *yes)
-                                      if test $ac_cv_func_vasprintf = yes; then
-                                        # vasprintf exists and is already POSIX
-                                        # compliant.
-                                        gl_cv_func_vasprintf_posix=yes
-                                      fi
+                                      case "$gl_cv_func_printf_flag_zero" in
+                                        *yes)
+                                          if test $ac_cv_func_vasprintf = yes; then
+                                            # vasprintf exists and is already
+                                            # POSIX compliant.
+                                            gl_cv_func_vasprintf_posix=yes
+                                          fi
+                                          ;;
+                                      esac
                                       ;;
                                   esac
                                   ;;
@@ -60,8 +65,9 @@
       ;;
   esac
   if test $gl_cv_func_vasprintf_posix = no; then
-    gl_PREREQ_VASNPRINTF_INFINITE
     gl_PREREQ_VASNPRINTF_LONG_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
     gl_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_PREREQ_VASNPRINTF_DIRECTIVE_F
     gl_PREREQ_VASNPRINTF_FLAG_GROUPING
--- a/m4/vfprintf-posix.m4
+++ b/m4/vfprintf-posix.m4
@@ -8,8 +8,9 @@
 [
   AC_REQUIRE([gl_EOVERFLOW])
   AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_INFINITE])
-  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
+  AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
@@ -19,25 +20,29 @@
   gl_cv_func_vfprintf_posix=no
   case "$gl_cv_func_printf_sizes_c99" in
     *yes)
-      case "$gl_cv_func_printf_infinite" in
+      case "$gl_cv_func_printf_long_double" in
         *yes)
-          case "$gl_cv_func_printf_long_double" in
+          case "$gl_cv_func_printf_infinite" in
             *yes)
-              case "$gl_cv_func_printf_directive_a" in
+              case "$gl_cv_func_printf_infinite_long_double" in
                 *yes)
-                  case "$gl_cv_func_printf_directive_f" in
+                  case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_n" in
+                      case "$gl_cv_func_printf_directive_f" in
                         *yes)
-                          case "$gl_cv_func_printf_positions" in
+                          case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_flag_grouping" in
+                              case "$gl_cv_func_printf_positions" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_zero" in
+                                  case "$gl_cv_func_printf_flag_grouping" in
                                     *yes)
-                                      # vfprintf exists and is already POSIX
-                                      # compliant.
-                                      gl_cv_func_vfprintf_posix=yes
+                                      case "$gl_cv_func_printf_flag_zero" in
+                                        *yes)
+                                          # vfprintf exists and is already
+                                          # POSIX compliant.
+                                          gl_cv_func_vfprintf_posix=yes
+                                          ;;
+                                      esac
                                       ;;
                                   esac
                                   ;;
@@ -57,8 +62,9 @@
       ;;
   esac
   if test $gl_cv_func_vfprintf_posix = no; then
-    gl_PREREQ_VASNPRINTF_INFINITE
     gl_PREREQ_VASNPRINTF_LONG_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
     gl_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_PREREQ_VASNPRINTF_DIRECTIVE_F
     gl_PREREQ_VASNPRINTF_FLAG_GROUPING
--- a/m4/vsnprintf-posix.m4
+++ b/m4/vsnprintf-posix.m4
@@ -8,8 +8,9 @@
 [
   AC_REQUIRE([gl_EOVERFLOW])
   AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_INFINITE])
-  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
+  AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
@@ -26,33 +27,37 @@
     gl_VSNPRINTF_ZEROSIZE_C99
     case "$gl_cv_func_printf_sizes_c99" in
       *yes)
-        case "$gl_cv_func_printf_infinite" in
+        case "$gl_cv_func_printf_long_double" in
           *yes)
-            case "$gl_cv_func_printf_long_double" in
+            case "$gl_cv_func_printf_infinite" in
               *yes)
-                case "$gl_cv_func_printf_directive_a" in
+                case "$gl_cv_func_printf_infinite_long_double" in
                   *yes)
-                    case "$gl_cv_func_printf_directive_f" in
+                    case "$gl_cv_func_printf_directive_a" in
                       *yes)
-                        case "$gl_cv_func_printf_directive_n" in
+                        case "$gl_cv_func_printf_directive_f" in
                           *yes)
-                            case "$gl_cv_func_printf_positions" in
+                            case "$gl_cv_func_printf_directive_n" in
                               *yes)
-                                case "$gl_cv_func_printf_flag_grouping" in
+                                case "$gl_cv_func_printf_positions" in
                                   *yes)
-                                    case "$gl_cv_func_printf_flag_zero" in
+                                    case "$gl_cv_func_printf_flag_grouping" in
                                       *yes)
-                                        case "$gl_cv_func_snprintf_truncation_c99" in
+                                        case "$gl_cv_func_printf_flag_zero" in
                                           *yes)
-                                            case "$gl_cv_func_snprintf_retval_c99" in
+                                            case "$gl_cv_func_snprintf_truncation_c99" in
                                               *yes)
-                                                case "$gl_cv_func_snprintf_directive_n" in
+                                                case "$gl_cv_func_snprintf_retval_c99" in
                                                   *yes)
-                                                    case "$gl_cv_func_vsnprintf_zerosize_c99" in
+                                                    case "$gl_cv_func_snprintf_directive_n" in
                                                       *yes)
-                                                        # vsnprintf exists and is
-                                                        # already POSIX compliant.
-                                                        gl_cv_func_vsnprintf_posix=yes
+                                                        case "$gl_cv_func_vsnprintf_zerosize_c99" in
+                                                          *yes)
+                                                            # vsnprintf exists and is
+                                                            # already POSIX compliant.
+                                                            gl_cv_func_vsnprintf_posix=yes
+                                                            ;;
+                                                        esac
                                                         ;;
                                                     esac
                                                     ;;
@@ -81,8 +86,9 @@
     esac
   fi
   if test $gl_cv_func_vsnprintf_posix = no; then
-    gl_PREREQ_VASNPRINTF_INFINITE
     gl_PREREQ_VASNPRINTF_LONG_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
     gl_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_PREREQ_VASNPRINTF_DIRECTIVE_F
     gl_PREREQ_VASNPRINTF_FLAG_GROUPING
--- a/m4/vsprintf-posix.m4
+++ b/m4/vsprintf-posix.m4
@@ -8,8 +8,9 @@
 [
   AC_REQUIRE([gl_EOVERFLOW])
   AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_INFINITE])
-  AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
+  AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
@@ -19,25 +20,29 @@
   gl_cv_func_vsprintf_posix=no
   case "$gl_cv_func_printf_sizes_c99" in
     *yes)
-      case "$gl_cv_func_printf_infinite" in
+      case "$gl_cv_func_printf_long_double" in
         *yes)
-          case "$gl_cv_func_printf_long_double" in
+          case "$gl_cv_func_printf_infinite" in
             *yes)
-              case "$gl_cv_func_printf_directive_a" in
+              case "$gl_cv_func_printf_infinite_long_double" in
                 *yes)
-                  case "$gl_cv_func_printf_directive_f" in
+                  case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_n" in
+                      case "$gl_cv_func_printf_directive_f" in
                         *yes)
-                          case "$gl_cv_func_printf_positions" in
+                          case "$gl_cv_func_printf_directive_n" in
                             *yes)
-                              case "$gl_cv_func_printf_flag_grouping" in
+                              case "$gl_cv_func_printf_positions" in
                                 *yes)
-                                  case "$gl_cv_func_printf_flag_zero" in
+                                  case "$gl_cv_func_printf_flag_grouping" in
                                     *yes)
-                                      # vsprintf exists and is already POSIX
-                                      # compliant.
-                                      gl_cv_func_vsprintf_posix=yes
+                                      case "$gl_cv_func_printf_flag_zero" in
+                                        *yes)
+                                          # vsprintf exists and is already
+                                          # POSIX compliant.
+                                          gl_cv_func_vsprintf_posix=yes
+                                          ;;
+                                      esac
                                       ;;
                                   esac
                                   ;;
@@ -57,8 +62,9 @@
       ;;
   esac
   if test $gl_cv_func_vsprintf_posix = no; then
-    gl_PREREQ_VASNPRINTF_INFINITE
     gl_PREREQ_VASNPRINTF_LONG_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
+    gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
     gl_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_PREREQ_VASNPRINTF_DIRECTIVE_F
     gl_PREREQ_VASNPRINTF_FLAG_GROUPING