| 1 |
# isnanf.m4 |
| 2 |
# serial 22 |
| 3 |
dnl Copyright (C) 2007-2026 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
dnl Check how to get or define isnanf(). |
| 10 |
|
| 11 |
AC_DEFUN([gl_FUNC_ISNANF], |
| 12 |
[ |
| 13 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 14 |
ISNANF_LIBM= |
| 15 |
gl_HAVE_ISNANF_NO_LIBM |
| 16 |
if test $gl_cv_func_isnanf_no_libm = no; then |
| 17 |
gl_HAVE_ISNANF_IN_LIBM |
| 18 |
if test $gl_cv_func_isnanf_in_libm = yes; then |
| 19 |
ISNANF_LIBM=-lm |
| 20 |
fi |
| 21 |
fi |
| 22 |
dnl The variable gl_func_isnanf set here is used by isnan.m4. |
| 23 |
if test $gl_cv_func_isnanf_no_libm = yes || test -n "$ISNANF_LIBM"; then |
| 24 |
saved_LIBS="$LIBS" |
| 25 |
LIBS="$LIBS $ISNANF_LIBM" |
| 26 |
gl_ISNANF_WORKS |
| 27 |
LIBS="$saved_LIBS" |
| 28 |
case "$gl_cv_func_isnanf_works" in |
| 29 |
*yes) gl_func_isnanf=yes ;; |
| 30 |
*) gl_func_isnanf=no; ISNANF_LIBM= ;; |
| 31 |
esac |
| 32 |
else |
| 33 |
gl_func_isnanf=no |
| 34 |
fi |
| 35 |
if test $gl_func_isnanf != yes; then |
| 36 |
HAVE_ISNANF=0 |
| 37 |
fi |
| 38 |
AC_SUBST([ISNANF_LIBM]) |
| 39 |
]) |
| 40 |
|
| 41 |
dnl Check how to get or define isnanf() without linking with libm. |
| 42 |
|
| 43 |
AC_DEFUN([gl_FUNC_ISNANF_NO_LIBM], |
| 44 |
[ |
| 45 |
gl_HAVE_ISNANF_NO_LIBM |
| 46 |
if test $gl_cv_func_isnanf_no_libm = yes; then |
| 47 |
gl_ISNANF_WORKS |
| 48 |
fi |
| 49 |
if test $gl_cv_func_isnanf_no_libm = yes \ |
| 50 |
&& { case "$gl_cv_func_isnanf_works" in |
| 51 |
*yes) true;; |
| 52 |
*) false;; |
| 53 |
esac |
| 54 |
}; then |
| 55 |
gl_func_isnanf_no_libm=yes |
| 56 |
AC_DEFINE([HAVE_ISNANF_IN_LIBC], [1], |
| 57 |
[Define if the isnan(float) function is available in libc.]) |
| 58 |
else |
| 59 |
gl_func_isnanf_no_libm=no |
| 60 |
fi |
| 61 |
]) |
| 62 |
|
| 63 |
dnl Prerequisites of replacement isnanf definition. It does not need -lm. |
| 64 |
AC_DEFUN([gl_PREREQ_ISNANF], |
| 65 |
[ |
| 66 |
gl_FLOAT_EXPONENT_LOCATION |
| 67 |
]) |
| 68 |
|
| 69 |
dnl Test whether isnanf() can be used without libm. |
| 70 |
AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM], |
| 71 |
[ |
| 72 |
AC_CACHE_CHECK([whether isnan(float) can be used without linking with libm], |
| 73 |
[gl_cv_func_isnanf_no_libm], |
| 74 |
[ |
| 75 |
AC_LINK_IFELSE( |
| 76 |
[AC_LANG_PROGRAM( |
| 77 |
[[#include <math.h> |
| 78 |
#if (__GNUC__ >= 4) || (__clang_major__ >= 4) |
| 79 |
# undef isnanf |
| 80 |
# define isnanf(x) __builtin_isnan ((float)(x)) |
| 81 |
#elif defined isnan |
| 82 |
# undef isnanf |
| 83 |
# define isnanf(x) isnan ((float)(x)) |
| 84 |
#endif |
| 85 |
float x;]], |
| 86 |
[[return isnanf (x);]])], |
| 87 |
[gl_cv_func_isnanf_no_libm=yes], |
| 88 |
[gl_cv_func_isnanf_no_libm=no]) |
| 89 |
]) |
| 90 |
]) |
| 91 |
|
| 92 |
dnl Test whether isnanf() can be used with libm. |
| 93 |
AC_DEFUN([gl_HAVE_ISNANF_IN_LIBM], |
| 94 |
[ |
| 95 |
AC_CACHE_CHECK([whether isnan(float) can be used with libm], |
| 96 |
[gl_cv_func_isnanf_in_libm], |
| 97 |
[ |
| 98 |
saved_LIBS="$LIBS" |
| 99 |
LIBS="$LIBS -lm" |
| 100 |
AC_LINK_IFELSE( |
| 101 |
[AC_LANG_PROGRAM( |
| 102 |
[[#include <math.h> |
| 103 |
#if (__GNUC__ >= 4) || (__clang_major__ >= 4) |
| 104 |
# undef isnanf |
| 105 |
# define isnanf(x) __builtin_isnan ((float)(x)) |
| 106 |
#elif defined isnan |
| 107 |
# undef isnanf |
| 108 |
# define isnanf(x) isnan ((float)(x)) |
| 109 |
#endif |
| 110 |
float x;]], |
| 111 |
[[return isnanf (x);]])], |
| 112 |
[gl_cv_func_isnanf_in_libm=yes], |
| 113 |
[gl_cv_func_isnanf_in_libm=no]) |
| 114 |
LIBS="$saved_LIBS" |
| 115 |
]) |
| 116 |
]) |
| 117 |
|
| 118 |
dnl Test whether isnanf() rejects Infinity (this fails on Solaris 2.5.1). |
| 119 |
AC_DEFUN([gl_ISNANF_WORKS], |
| 120 |
[ |
| 121 |
AC_REQUIRE([AC_PROG_CC]) |
| 122 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 123 |
AC_REQUIRE([gl_FLOAT_EXPONENT_LOCATION]) |
| 124 |
AC_CACHE_CHECK([whether isnan(float) works], [gl_cv_func_isnanf_works], |
| 125 |
[ |
| 126 |
AC_RUN_IFELSE( |
| 127 |
[AC_LANG_SOURCE([[ |
| 128 |
#include <math.h> |
| 129 |
#if (__GNUC__ >= 4) || (__clang_major__ >= 4) |
| 130 |
# undef isnanf |
| 131 |
# define isnanf(x) __builtin_isnan ((float)(x)) |
| 132 |
#elif defined isnan |
| 133 |
# undef isnanf |
| 134 |
# define isnanf(x) isnan ((float)(x)) |
| 135 |
#endif |
| 136 |
int main() |
| 137 |
{ |
| 138 |
int result = 0; |
| 139 |
|
| 140 |
if (isnanf (1.0f / 0.0f)) |
| 141 |
result |= 1; |
| 142 |
|
| 143 |
return result; |
| 144 |
}]])], |
| 145 |
[gl_cv_func_isnanf_works=yes], |
| 146 |
[gl_cv_func_isnanf_works=no], |
| 147 |
[case "$host_os" in |
| 148 |
solaris*) gl_cv_func_isnanf_works="guessing no" ;; |
| 149 |
mingw* | windows*) # Guess yes on mingw, no on MSVC. |
| 150 |
AC_EGREP_CPP([Known], [ |
| 151 |
#ifdef __MINGW32__ |
| 152 |
Known |
| 153 |
#endif |
| 154 |
], |
| 155 |
[gl_cv_func_isnanf_works="guessing yes"], |
| 156 |
[gl_cv_func_isnanf_works="guessing no"]) |
| 157 |
;; |
| 158 |
*) gl_cv_func_isnanf_works="guessing yes" ;; |
| 159 |
esac |
| 160 |
]) |
| 161 |
]) |
| 162 |
]) |