Move macros for finding floating-point exponents into separate M4 files.
[gnulib.git] / m4 / isnand.m4
1 # isnand.m4 serial 4
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.
6
7 dnl Check how to get or define isnand().
8 AC_DEFUN([gl_FUNC_ISNAND],
9 [
10   ISNAND_LIBM=
11   gl_HAVE_ISNAND_NO_LIBM
12   if test $gl_cv_func_isnand_no_libm = no; then
13     gl_HAVE_ISNAND_IN_LIBM
14     if test $gl_cv_func_isnand_in_libm = yes; then
15       ISNAND_LIBM=-lm
16     fi
17   fi
18   dnl The variable gl_func_isnand set here is used by isnan.m4.
19   if test $gl_cv_func_isnand_no_libm = yes \
20      || test $gl_cv_func_isnand_in_libm = yes; then
21     gl_func_isnand=yes
22     AC_DEFINE([HAVE_ISNAND], 1,
23       [Define if the isnan(double) function is available.])
24   else
25     gl_func_isnand=no
26     gl_BUILD_ISNAND
27   fi
28   AC_SUBST([ISNAND_LIBM])
29 ])
30
31 dnl Check how to get or define isnand() without linking with libm.
32
33 AC_DEFUN([gl_FUNC_ISNAND_NO_LIBM],
34 [
35   gl_HAVE_ISNAND_NO_LIBM
36   if test $gl_cv_func_isnand_no_libm = yes; then
37     AC_DEFINE([HAVE_ISNAND_IN_LIBC], 1,
38       [Define if the isnan(double) function is available in libc.])
39   else
40     gl_BUILD_ISNAND
41   fi
42 ])
43
44 dnl Pull in replacement isnand definition. It does not need -lm.
45 AC_DEFUN([gl_BUILD_ISNAND],
46 [
47   AC_LIBOBJ([isnand])
48   gl_DOUBLE_EXPONENT_LOCATION
49 ])
50
51 dnl Test whether isnand() can be used with libm.
52
53 AC_DEFUN([gl_HAVE_ISNAND_IN_LIBM],
54 [
55   AC_CACHE_CHECK([whether isnan(double) can be used with libm],
56     [gl_cv_func_isnand_in_libm],
57     [
58       save_LIBS="$LIBS"
59       LIBS="$LIBS -lm"
60       AC_TRY_LINK([#include <math.h>
61                    #if __GNUC__ >= 4
62                    # undef isnand
63                    # define isnand(x) __builtin_isnand ((double)(x))
64                    #elif defined isnan
65                    # undef isnand
66                    # define isnand(x) isnan ((double)(x))
67                    #endif
68                    double x;],
69                   [return isnand (x);],
70         [gl_cv_func_isnand_in_libm=yes],
71         [gl_cv_func_isnand_in_libm=no])
72       LIBS="$save_LIBS"
73     ])
74 ])
75
76 AC_DEFUN([gl_HAVE_ISNAND_NO_LIBM],
77 [
78   AC_CACHE_CHECK([whether isnan(double) can be used without linking with libm],
79     [gl_cv_func_isnand_no_libm],
80     [
81       AC_TRY_LINK([#include <math.h>
82                    #if __GNUC__ >= 4
83                    # undef isnand
84                    # define isnand(x) __builtin_isnan ((double)(x))
85                    #else
86                    # undef isnand
87                    # define isnand(x) isnan ((double)(x))
88                    #endif
89                    double x;],
90                   [return isnand (x);],
91         [gl_cv_func_isnand_no_libm=yes],
92         [gl_cv_func_isnand_no_libm=no])
93     ])
94 ])