maint: update copyright
[gnulib.git] / m4 / fmodl.m4
1 # fmodl.m4 serial 5
2 dnl Copyright (C) 2011-2014 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 AC_DEFUN([gl_FUNC_FMODL],
8 [
9   m4_divert_text([DEFAULTS], [gl_fmodl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_FMOD])
13
14   dnl Persuade glibc <math.h> to declare fmodl().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16
17   dnl Test whether fmodl() is declared.
18   dnl AIX 5.1 has fmodl() in libc but doesn't declare it in <math.h>, and the
19   dnl function produces NaN results for finite values.
20   AC_CHECK_DECL([fmodl],
21     [ac_cv_have_decl_fmodl=yes], [ac_cv_have_decl_fmodl=no],
22     [[#include <math.h>]])
23
24   dnl Test whether fmodl() exists. Assume that fmodl(), if it exists, is
25   dnl defined in the same library as fmod().
26   save_LIBS="$LIBS"
27   LIBS="$LIBS $FMOD_LIBM"
28   AC_CHECK_FUNCS([fmodl])
29   LIBS="$save_LIBS"
30   if test $ac_cv_func_fmodl = yes; then
31     FMODL_LIBM="$FMOD_LIBM"
32     if test $ac_cv_have_decl_fmodl = no; then
33       REPLACE_FMODL=1
34     fi
35     m4_ifdef([gl_FUNC_FMODL_IEEE], [
36       if test $gl_fmodl_required = ieee && test $REPLACE_FMODL = 0; then
37         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
38         AC_CACHE_CHECK([whether fmodl works according to ISO C 99 with IEC 60559],
39           [gl_cv_func_fmodl_ieee],
40           [
41             save_LIBS="$LIBS"
42             LIBS="$LIBS $FMODL_LIBM"
43             AC_RUN_IFELSE(
44               [AC_LANG_SOURCE([[
45 #ifndef __NO_MATH_INLINES
46 # define __NO_MATH_INLINES 1 /* for glibc */
47 #endif
48 #include <math.h>
49 /* Compare two numbers with ==.
50    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
51    'x == x' test.  */
52 static int
53 numeric_equal (long double x, long double y)
54 {
55   return x == y;
56 }
57 static long double dummy (long double x, long double y) { return 0; }
58 int main (int argc, char *argv[])
59 {
60   long double (*my_fmodl) (long double, long double) = argc ? fmodl : dummy;
61   long double f;
62   /* Test fmodl(...,0.0L).
63      This test fails on OSF/1 5.1.  */
64   f = my_fmodl (2.0L, 0.0L);
65   if (numeric_equal (f, f))
66     return 1;
67   return 0;
68 }
69               ]])],
70               [gl_cv_func_fmodl_ieee=yes],
71               [gl_cv_func_fmodl_ieee=no],
72               [case "$host_os" in
73                          # Guess yes on glibc systems.
74                  *-gnu*) gl_cv_func_fmodl_ieee="guessing yes" ;;
75                          # If we don't know, assume the worst.
76                  *)      gl_cv_func_fmodl_ieee="guessing no" ;;
77                esac
78               ])
79             LIBS="$save_LIBS"
80           ])
81         case "$gl_cv_func_fmodl_ieee" in
82           *yes) ;;
83           *) REPLACE_FMODL=1 ;;
84         esac
85       fi
86     ])
87   else
88     HAVE_FMODL=0
89   fi
90   if test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; then
91     dnl Find libraries needed to link lib/fmodl.c.
92     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
93       FMODL_LIBM="$FMOD_LIBM"
94     else
95       AC_REQUIRE([gl_FUNC_FABSL])
96       AC_REQUIRE([gl_FUNC_FREXPL])
97       AC_REQUIRE([gl_FUNC_TRUNCL])
98       AC_REQUIRE([gl_FUNC_LDEXPL])
99       AC_REQUIRE([gl_FUNC_ISNANL])
100       FMODL_LIBM=
101       dnl Append $FABSL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
102       case " $FMODL_LIBM " in
103         *" $FABSL_LIBM "*) ;;
104         *) FMODL_LIBM="$FMODL_LIBM $FABSL_LIBM" ;;
105       esac
106       dnl Append $FREXPL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
107       case " $FMODL_LIBM " in
108         *" $FREXPL_LIBM "*) ;;
109         *) FMODL_LIBM="$FMODL_LIBM $FREXPL_LIBM" ;;
110       esac
111       dnl Append $TRUNCL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
112       case " $FMODL_LIBM " in
113         *" $TRUNCL_LIBM "*) ;;
114         *) FMODL_LIBM="$FMODL_LIBM $TRUNCL_LIBM" ;;
115       esac
116       dnl Append $LDEXPL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
117       case " $FMODL_LIBM " in
118         *" $LDEXPL_LIBM "*) ;;
119         *) FMODL_LIBM="$FMODL_LIBM $LDEXPL_LIBM" ;;
120       esac
121       dnl Append $ISNANL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
122       case " $FMODL_LIBM " in
123         *" $ISNANL_LIBM "*) ;;
124         *) FMODL_LIBM="$FMODL_LIBM $ISNANL_LIBM" ;;
125       esac
126     fi
127   fi
128   AC_SUBST([FMODL_LIBM])
129 ])