New module 'log-ieee'.
[gnulib.git] / m4 / remainderl.m4
1 # remainderl.m4 serial 5
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     m4_ifdef([gl_FUNC_REMAINDERL_IEEE], [
51       if test $gl_remainderl_required = ieee && test $REPLACE_REMAINDERL = 0; then
52         AC_CACHE_CHECK([whether remainderl works according to ISO C 99 with IEC 60559],
53           [gl_cv_func_remainderl_ieee],
54           [
55             save_LIBS="$LIBS"
56             LIBS="$LIBS $REMAINDERL_LIBM"
57             AC_RUN_IFELSE(
58               [AC_LANG_SOURCE([[
59 #ifndef __NO_MATH_INLINES
60 # define __NO_MATH_INLINES 1 /* for glibc */
61 #endif
62 #include <math.h>
63 extern
64 #ifdef __cplusplus
65 "C"
66 #endif
67 long double remainderl (long double, long double);
68 /* Compare two numbers with ==.
69    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
70    'x == x' test.  */
71 static int
72 numeric_equal (long double x, long double y)
73 {
74   return x == y;
75 }
76 static long double dummy (long double x, long double y) { return 0; }
77 int main (int argc, char *argv[])
78 {
79   long double (*my_remainderl) (long double, long double) = argc ? remainderl : dummy;
80   long double f;
81   /* Test remainderl(...,0.0L).
82      This test fails on OSF/1 5.1.  */
83   f = my_remainderl (2.0L, 0.0L);
84   if (numeric_equal (f, f))
85     return 1;
86   return 0;
87 }
88               ]])],
89               [gl_cv_func_remainderl_ieee=yes],
90               [gl_cv_func_remainderl_ieee=no],
91               [gl_cv_func_remainderl_ieee="guessing no"])
92             LIBS="$save_LIBS"
93           ])
94         case "$gl_cv_func_remainderl_ieee" in
95           *yes) ;;
96           *) REPLACE_REMAINDERL=1 ;;
97         esac
98       fi
99     ])
100   else
101     HAVE_REMAINDERL=0
102     HAVE_DECL_REMAINDERL=0
103   fi
104   if test $HAVE_REMAINDERL = 0 || test $REPLACE_REMAINDERL = 1; then
105     dnl Find libraries needed to link lib/remainderl.c.
106     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
107       REMAINDERL_LIBM="$REMAINDER_LIBM"
108     else
109       AC_REQUIRE([gl_FUNC_FABSL])
110       AC_REQUIRE([gl_FUNC_FMODL])
111       AC_REQUIRE([gl_FUNC_ISNANL])
112       REMAINDERL_LIBM=
113       dnl Append $FABSL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
114       case " $REMAINDERL_LIBM " in
115         *" $FABSL_LIBM "*) ;;
116         *) REMAINDERL_LIBM="$REMAINDERL_LIBM $FABSL_LIBM" ;;
117       esac
118       dnl Append $FMODL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
119       case " $REMAINDERL_LIBM " in
120         *" $FMODL_LIBM "*) ;;
121         *) REMAINDERL_LIBM="$REMAINDERL_LIBM $FMODL_LIBM" ;;
122       esac
123       dnl Append $ISNANL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
124       case " $REMAINDERL_LIBM " in
125         *" $ISNANL_LIBM "*) ;;
126         *) REMAINDERL_LIBM="$REMAINDERL_LIBM $ISNANL_LIBM" ;;
127       esac
128     fi
129   fi
130   AC_SUBST([REMAINDERL_LIBM])
131 ])