bump standards-version
[gnulib.git] / m4 / remainder.m4
1 # remainder.m4 serial 3
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_REMAINDER],
8 [
9   m4_divert_text([DEFAULTS], [gl_remainder_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11
12   dnl Test whether remainder() is declared. On IRIX 5.3 it is not declared.
13   AC_CHECK_DECL([remainder], , [HAVE_DECL_REMAINDER=0], [[#include <math.h>]])
14
15   REMAINDER_LIBM=
16   AC_CACHE_CHECK([whether remainder() can be used without linking with libm],
17     [gl_cv_func_remainder_no_libm],
18     [
19       AC_LINK_IFELSE(
20         [AC_LANG_PROGRAM(
21            [[#ifndef __NO_MATH_INLINES
22              # define __NO_MATH_INLINES 1 /* for glibc */
23              #endif
24              #include <math.h>
25              double x;
26              double y;]],
27            [[return remainder (x, y) > 1;]])],
28         [gl_cv_func_remainder_no_libm=yes],
29         [gl_cv_func_remainder_no_libm=no])
30     ])
31   if test $gl_cv_func_remainder_no_libm = no; then
32     AC_CACHE_CHECK([whether remainder() can be used with libm],
33       [gl_cv_func_remainder_in_libm],
34       [
35         save_LIBS="$LIBS"
36         LIBS="$LIBS -lm"
37         AC_LINK_IFELSE(
38           [AC_LANG_PROGRAM(
39              [[#ifndef __NO_MATH_INLINES
40                # define __NO_MATH_INLINES 1 /* for glibc */
41                #endif
42                #include <math.h>
43                double x;
44                double y;]],
45              [[return remainder (x, y) > 1;]])],
46           [gl_cv_func_remainder_in_libm=yes],
47           [gl_cv_func_remainder_in_libm=no])
48         LIBS="$save_LIBS"
49       ])
50     if test $gl_cv_func_remainder_in_libm = yes; then
51       REMAINDER_LIBM=-lm
52     fi
53   fi
54   if test $gl_cv_func_remainder_no_libm = yes \
55      || test $gl_cv_func_remainder_in_libm = yes; then
56     :
57     m4_ifdef([gl_FUNC_REMAINDER_IEEE], [
58       if test $gl_remainder_required = ieee && test $REPLACE_REMAINDER = 0; then
59         AC_CACHE_CHECK([whether remainder works according to ISO C 99 with IEC 60559],
60           [gl_cv_func_remainder_ieee],
61           [
62             save_LIBS="$LIBS"
63             LIBS="$LIBS $REMAINDER_LIBM"
64             AC_RUN_IFELSE(
65               [AC_LANG_SOURCE([[
66 #ifndef __NO_MATH_INLINES
67 # define __NO_MATH_INLINES 1 /* for glibc */
68 #endif
69 #include <math.h>
70 /* Compare two numbers with ==.
71    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
72    'x == x' test.  */
73 static int
74 numeric_equal (double x, double y)
75 {
76   return x == y;
77 }
78 static double dummy (double x, double y) { return 0; }
79 int main (int argc, char *argv[])
80 {
81   double (*my_remainder) (double, double) = argc ? remainder : dummy;
82   double f;
83   /* Test remainder(...,0.0).
84      This test fails on OSF/1 5.1.  */
85   f = my_remainder (2.0, 0.0);
86   if (numeric_equal (f, f))
87     return 1;
88   return 0;
89 }
90               ]])],
91               [gl_cv_func_remainder_ieee=yes],
92               [gl_cv_func_remainder_ieee=no],
93               [gl_cv_func_remainder_ieee="guessing no"])
94             LIBS="$save_LIBS"
95           ])
96         case "$gl_cv_func_remainder_ieee" in
97           *yes) ;;
98           *) REPLACE_REMAINDER=1 ;;
99         esac
100       fi
101     ])
102   else
103     HAVE_REMAINDER=0
104   fi
105   if test $HAVE_REMAINDER = 0 || test $REPLACE_REMAINDER = 1; then
106     dnl Find libraries needed to link lib/remainder.c.
107     AC_REQUIRE([gl_FUNC_FABS])
108     AC_REQUIRE([gl_FUNC_FMOD])
109     AC_REQUIRE([gl_FUNC_ISNAND])
110     REMAINDER_LIBM=
111     dnl Append $FABS_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates.
112     case " $REMAINDER_LIBM " in
113       *" $FABS_LIBM "*) ;;
114       *) REMAINDER_LIBM="$REMAINDER_LIBM $FABS_LIBM" ;;
115     esac
116     dnl Append $FMOD_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates.
117     case " $REMAINDER_LIBM " in
118       *" $FMOD_LIBM "*) ;;
119       *) REMAINDER_LIBM="$REMAINDER_LIBM $FMOD_LIBM" ;;
120     esac
121     dnl Append $ISNAND_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates.
122     case " $REMAINDER_LIBM " in
123       *" $ISNAND_LIBM "*) ;;
124       *) REMAINDER_LIBM="$REMAINDER_LIBM $ISNAND_LIBM" ;;
125     esac
126   fi
127   AC_SUBST([REMAINDER_LIBM])
128 ])