2 dnl Copyright (C) 2007-2020 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],
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
13 gl_HAVE_ISNANF_NO_LIBM
14 if test $gl_cv_func_isnanf_no_libm = no; then
15 gl_HAVE_ISNANF_IN_LIBM
16 if test $gl_cv_func_isnanf_in_libm = yes; then
20 dnl The variable gl_func_isnanf set here is used by isnan.m4.
21 if test $gl_cv_func_isnanf_no_libm = yes \
22 || test $gl_cv_func_isnanf_in_libm = yes; then
24 LIBS="$LIBS $ISNANF_LIBM"
27 case "$gl_cv_func_isnanf_works" in
28 *yes) gl_func_isnanf=yes ;;
29 *) gl_func_isnanf=no; ISNANF_LIBM= ;;
34 if test $gl_func_isnanf != yes; then
37 AC_SUBST([ISNANF_LIBM])
40 dnl Check how to get or define isnanf() without linking with libm.
42 AC_DEFUN([gl_FUNC_ISNANF_NO_LIBM],
44 gl_HAVE_ISNANF_NO_LIBM
45 if test $gl_cv_func_isnanf_no_libm = yes; then
48 if test $gl_cv_func_isnanf_no_libm = yes \
49 && { case "$gl_cv_func_isnanf_works" in
54 gl_func_isnanf_no_libm=yes
55 AC_DEFINE([HAVE_ISNANF_IN_LIBC], [1],
56 [Define if the isnan(float) function is available in libc.])
58 gl_func_isnanf_no_libm=no
62 dnl Prerequisites of replacement isnanf definition. It does not need -lm.
63 AC_DEFUN([gl_PREREQ_ISNANF],
65 gl_FLOAT_EXPONENT_LOCATION
68 dnl Test whether isnanf() can be used without libm.
69 AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM],
71 AC_CACHE_CHECK([whether isnan(float) can be used without linking with libm],
72 [gl_cv_func_isnanf_no_libm],
77 #if (__GNUC__ >= 4) || (__clang_major__ >= 4)
79 # define isnanf(x) __builtin_isnan ((float)(x))
82 # define isnanf(x) isnan ((float)(x))
85 [[return isnanf (x);]])],
86 [gl_cv_func_isnanf_no_libm=yes],
87 [gl_cv_func_isnanf_no_libm=no])
91 dnl Test whether isnanf() can be used with libm.
92 AC_DEFUN([gl_HAVE_ISNANF_IN_LIBM],
94 AC_CACHE_CHECK([whether isnan(float) can be used with libm],
95 [gl_cv_func_isnanf_in_libm],
102 #if (__GNUC__ >= 4) || (__clang_major__ >= 4)
104 # define isnanf(x) __builtin_isnan ((float)(x))
107 # define isnanf(x) isnan ((float)(x))
110 [[return isnanf (x);]])],
111 [gl_cv_func_isnanf_in_libm=yes],
112 [gl_cv_func_isnanf_in_libm=no])
117 dnl Test whether isnanf() rejects Infinity (this fails on Solaris 2.5.1),
118 dnl recognizes a NaN (this fails on IRIX 6.5 with cc), and recognizes a NaN
119 dnl with in-memory representation 0x7fbfffff (this fails on IRIX 6.5).
120 AC_DEFUN([gl_ISNANF_WORKS],
122 AC_REQUIRE([AC_PROG_CC])
123 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
124 AC_REQUIRE([gl_FLOAT_EXPONENT_LOCATION])
125 AC_CACHE_CHECK([whether isnan(float) works], [gl_cv_func_isnanf_works],
130 #if (__GNUC__ >= 4) || (__clang_major__ >= 4)
132 # define isnanf(x) __builtin_isnan ((float)(x))
135 # define isnanf(x) isnan ((float)(x))
137 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
142 static float zero = 0.0f;
146 # define NaN() (0.0f / 0.0f)
149 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
150 typedef union { unsigned int word[NWORDS]; float value; } memory_float;
155 if (isnanf (1.0f / 0.0f))
158 if (!isnanf (NaN ()))
161 #if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
162 /* The isnanf function should be immune against changes in the sign bit and
163 in the mantissa bits. The xor operation twiddles a bit that can only be
164 a sign bit or a mantissa bit. */
165 if (FLT_EXPBIT0_WORD == 0 && FLT_EXPBIT0_BIT > 0)
170 /* Set the bits below the exponent to 01111...111. */
171 m.word[0] &= -1U << FLT_EXPBIT0_BIT;
172 m.word[0] |= 1U << (FLT_EXPBIT0_BIT - 1) - 1;
173 if (!isnanf (m.value))
180 [gl_cv_func_isnanf_works=yes],
181 [gl_cv_func_isnanf_works=no],
183 irix* | solaris*) gl_cv_func_isnanf_works="guessing no" ;;
184 mingw*) # Guess yes on mingw, no on MSVC.
185 AC_EGREP_CPP([Known], [
190 [gl_cv_func_isnanf_works="guessing yes"],
191 [gl_cv_func_isnanf_works="guessing no"])
193 *) gl_cv_func_isnanf_works="guessing yes" ;;