2 dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl Check how to get or define isnanf().
9 AC_DEFUN([gl_FUNC_ISNANF],
12 gl_HAVE_ISNANF_NO_LIBM
13 if test $gl_cv_func_isnanf_no_libm = no; then
14 gl_HAVE_ISNANF_IN_LIBM
15 if test $gl_cv_func_isnanf_in_libm = yes; then
19 if test $gl_cv_func_isnanf_no_libm = yes \
20 || test $gl_cv_func_isnanf_in_libm = yes; then
22 LIBS="$LIBS $ISNANF_LIBM"
25 case "$gl_cv_func_isnanf_works" in
26 *yes) gl_func_isnanf=yes ;;
27 *) gl_func_isnanf=no; ISNANF_LIBM= ;;
32 if test $gl_func_isnanf = yes; then
33 AC_DEFINE([HAVE_ISNANF], 1,
34 [Define if the isnan(float) function is available.])
38 AC_SUBST([ISNANF_LIBM])
41 dnl Check how to get or define isnanf() without linking with libm.
43 AC_DEFUN([gl_FUNC_ISNANF_NO_LIBM],
45 gl_HAVE_ISNANF_NO_LIBM
46 if test $gl_cv_func_isnanf_no_libm = yes; then
49 if test $gl_cv_func_isnanf_no_libm = yes \
50 && { case "$gl_cv_func_isnanf_works" in
55 AC_DEFINE([HAVE_ISNANF_IN_LIBC], 1,
56 [Define if the isnan(float) function is available in libc.])
62 dnl Pull in replacement isnanf definition. It does not need -lm.
63 AC_DEFUN([gl_BUILD_ISNANF],
66 gl_FLOAT_EXPONENT_LOCATION
69 dnl Test whether isnanf() can be used without libm.
70 AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM],
72 AC_CACHE_CHECK([whether isnan(float) can be used without linking with libm],
73 [gl_cv_func_isnanf_no_libm],
75 AC_TRY_LINK([#include <math.h>
78 # define isnanf(x) __builtin_isnanf ((float)(x))
81 # define isnanf(x) isnan ((float)(x))
85 [gl_cv_func_isnanf_no_libm=yes],
86 [gl_cv_func_isnanf_no_libm=no])
90 dnl Test whether isnanf() can be used with libm.
91 AC_DEFUN([gl_HAVE_ISNANF_IN_LIBM],
93 AC_CACHE_CHECK([whether isnan(float) can be used with libm],
94 [gl_cv_func_isnanf_in_libm],
98 AC_TRY_LINK([#include <math.h>
101 # define isnanf(x) __builtin_isnanf ((float)(x))
104 # define isnanf(x) isnan ((float)(x))
107 [return isnanf (x);],
108 [gl_cv_func_isnanf_in_libm=yes],
109 [gl_cv_func_isnanf_in_libm=no])
114 dnl Test whether isnanf() rejects Infinity (this fails on Solaris 2.5.1),
115 dnl recognizes a NaN (this fails on IRIX 6.5 with cc), and recognizes a NaN
116 dnl with in-memory representation 0x7fbfffff (this fails on IRIX 6.5).
117 AC_DEFUN([gl_ISNANF_WORKS],
119 AC_REQUIRE([AC_PROG_CC])
120 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
121 AC_REQUIRE([gl_FLOAT_EXPONENT_LOCATION])
122 AC_CACHE_CHECK([whether isnan(float) works], [gl_cv_func_isnanf_works],
128 # define isnanf(x) __builtin_isnanf ((float)(x))
131 # define isnanf(x) isnan ((float)(x))
133 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
138 static float zero = 0.0f;
142 # define NaN() (0.0f / 0.0f)
145 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
146 typedef union { unsigned int word[NWORDS]; float value; } memory_float;
151 if (isnanf (1.0f / 0.0f))
154 if (!isnanf (NaN ()))
157 #if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
158 /* The isnanf function should be immune against changes in the sign bit and
159 in the mantissa bits. The xor operation twiddles a bit that can only be
160 a sign bit or a mantissa bit. */
161 if (FLT_EXPBIT0_WORD == 0 && FLT_EXPBIT0_BIT > 0)
164 /* Set the bits below the exponent to 01111...111. */
165 m.word[0] &= -1U << FLT_EXPBIT0_BIT;
166 m.word[0] |= 1U << (FLT_EXPBIT0_BIT - 1) - 1;
167 if (!isnanf (m.value))
173 }], [gl_cv_func_isnanf_works=yes], [gl_cv_func_isnanf_works=no],
175 irix* | solaris*) gl_cv_func_isnanf_works="guessing no";;
176 *) gl_cv_func_isnanf_works="guessing yes";;