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