bump standards-version
[gnulib.git] / m4 / remainderl.m4
1 # remainderl.m4 serial 6
2 dnl Copyright (C) 2012 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_REMAINDERL],
8 [
9   m4_divert_text([DEFAULTS], [gl_remainderl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_REMAINDER])
13
14   dnl Persuade glibc <math.h> to declare remainderl().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16
17   dnl Test whether remainderl() exists. Assume that remainderl(), if it exists, is
18   dnl defined in the same library as remainder().
19   save_LIBS="$LIBS"
20   LIBS="$LIBS $REMAINDER_LIBM"
21   AC_CACHE_CHECK([for remainderl],
22     [gl_cv_func_remainderl],
23     [
24       AC_LINK_IFELSE(
25         [AC_LANG_PROGRAM(
26            [[#ifndef __NO_MATH_INLINES
27              # define __NO_MATH_INLINES 1 /* for glibc */
28              #endif
29              #include <math.h>
30              extern
31              #ifdef __cplusplus
32              "C"
33              #endif
34              long double remainderl (long double, long double);
35              long double (*funcptr) (long double, long double) = remainderl;
36              long double x;
37              long double y;]],
38            [[return funcptr (x, y) > 1
39                     || remainderl (x, y) > 1;]])],
40         [gl_cv_func_remainderl=yes],
41         [gl_cv_func_remainderl=no])
42     ])
43   LIBS="$save_LIBS"
44   if test $gl_cv_func_remainderl = yes; then
45     HAVE_REMAINDERL=1
46     REMAINDERL_LIBM="$REMAINDER_LIBM"
47     dnl Also check whether it's declared.
48     dnl IRIX 6.5 has remainderl() in libm but doesn't declare it in <math.h>.
49     AC_CHECK_DECLS([remainderl], , [HAVE_DECL_REMAINDERL=0], [[#include <math.h>]])
50
51     save_LIBS="$LIBS"
52     LIBS="$LIBS $REMAINDERL_LIBM"
53     gl_FUNC_REMAINDERL_WORKS
54     LIBS="$save_LIBS"
55     case "$gl_cv_func_remainderl_works" in
56       *yes) ;;
57       *) REPLACE_REMAINDERL=1 ;;
58     esac
59
60     m4_ifdef([gl_FUNC_REMAINDERL_IEEE], [
61       if test $gl_remainderl_required = ieee && test $REPLACE_REMAINDERL = 0; then
62         AC_CACHE_CHECK([whether remainderl works according to ISO C 99 with IEC 60559],
63           [gl_cv_func_remainderl_ieee],
64           [
65             save_LIBS="$LIBS"
66             LIBS="$LIBS $REMAINDERL_LIBM"
67             AC_RUN_IFELSE(
68               [AC_LANG_SOURCE([[
69 #ifndef __NO_MATH_INLINES
70 # define __NO_MATH_INLINES 1 /* for glibc */
71 #endif
72 #include <math.h>
73 extern
74 #ifdef __cplusplus
75 "C"
76 #endif
77 long double remainderl (long double, long double);
78 /* Compare two numbers with ==.
79    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
80    'x == x' test.  */
81 static int
82 numeric_equal (long double x, long double y)
83 {
84   return x == y;
85 }
86 static long double dummy (long double x, long double y) { return 0; }
87 int main (int argc, char *argv[])
88 {
89   long double (*my_remainderl) (long double, long double) = argc ? remainderl : dummy;
90   long double f;
91   /* Test remainderl(...,0.0L).
92      This test fails on OSF/1 5.1.  */
93   f = my_remainderl (2.0L, 0.0L);
94   if (numeric_equal (f, f))
95     return 1;
96   return 0;
97 }
98               ]])],
99               [gl_cv_func_remainderl_ieee=yes],
100               [gl_cv_func_remainderl_ieee=no],
101               [gl_cv_func_remainderl_ieee="guessing no"])
102             LIBS="$save_LIBS"
103           ])
104         case "$gl_cv_func_remainderl_ieee" in
105           *yes) ;;
106           *) REPLACE_REMAINDERL=1 ;;
107         esac
108       fi
109     ])
110   else
111     HAVE_REMAINDERL=0
112     HAVE_DECL_REMAINDERL=0
113   fi
114   if test $HAVE_REMAINDERL = 0 || test $REPLACE_REMAINDERL = 1; then
115     dnl Find libraries needed to link lib/remainderl.c.
116     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
117       REMAINDERL_LIBM="$REMAINDER_LIBM"
118     else
119       AC_REQUIRE([gl_FUNC_FABSL])
120       AC_REQUIRE([gl_FUNC_FMODL])
121       AC_REQUIRE([gl_FUNC_ISNANL])
122       REMAINDERL_LIBM=
123       dnl Append $FABSL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
124       case " $REMAINDERL_LIBM " in
125         *" $FABSL_LIBM "*) ;;
126         *) REMAINDERL_LIBM="$REMAINDERL_LIBM $FABSL_LIBM" ;;
127       esac
128       dnl Append $FMODL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
129       case " $REMAINDERL_LIBM " in
130         *" $FMODL_LIBM "*) ;;
131         *) REMAINDERL_LIBM="$REMAINDERL_LIBM $FMODL_LIBM" ;;
132       esac
133       dnl Append $ISNANL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
134       case " $REMAINDERL_LIBM " in
135         *" $ISNANL_LIBM "*) ;;
136         *) REMAINDERL_LIBM="$REMAINDERL_LIBM $ISNANL_LIBM" ;;
137       esac
138     fi
139   fi
140   AC_SUBST([REMAINDERL_LIBM])
141 ])
142
143 dnl Test whether remainderl() works.
144 dnl It produces completely wrong values on OpenBSD 5.1/SPARC.
145 AC_DEFUN([gl_FUNC_REMAINDERL_WORKS],
146 [
147   AC_REQUIRE([AC_PROG_CC])
148   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
149   AC_CACHE_CHECK([whether remainderl works], [gl_cv_func_remainderl_works],
150     [
151       AC_RUN_IFELSE(
152         [AC_LANG_SOURCE([[
153 #ifndef __NO_MATH_INLINES
154 # define __NO_MATH_INLINES 1 /* for glibc */
155 #endif
156 #include <math.h>
157 extern
158 #ifdef __cplusplus
159 "C"
160 #endif
161 long double remainderl (long double, long double);
162 volatile long double x;
163 volatile long double y;
164 long double z;
165 int main ()
166 {
167   /* This test fails on OpenBSD 5.1/SPARC.  */
168   x = 9.245907126L;
169   y = 3.141592654L;
170   z = remainderl (x, y);
171   if (z >= 0.0L)
172     return 1;
173   return 0;
174 }
175 ]])],
176         [gl_cv_func_remainderl_works=yes],
177         [gl_cv_func_remainderl_works=no],
178         [case "$host_os" in
179            openbsd*) gl_cv_func_remainderl_works="guessing no";;
180            *)        gl_cv_func_remainderl_works="guessing yes";;
181          esac
182         ])
183     ])
184 ])