26dd47e1e0d0f1882fdcd2142bca33af9a2d8e3f
[gnulib.git] / m4 / fmod.m4
1 # fmod.m4 serial 3
2 dnl Copyright (C) 2011-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_FMOD],
8 [
9   m4_divert_text([DEFAULTS], [gl_fmod_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11
12   dnl Determine FMOD_LIBM.
13   gl_COMMON_DOUBLE_MATHFUNC([fmod])
14
15   m4_ifdef([gl_FUNC_FMOD_IEEE], [
16     if test $gl_fmod_required = ieee && test $REPLACE_FMOD = 0; then
17       AC_CACHE_CHECK([whether fmod works according to ISO C 99 with IEC 60559],
18         [gl_cv_func_fmod_ieee],
19         [
20           save_LIBS="$LIBS"
21           LIBS="$LIBS $FMOD_LIBM"
22           AC_RUN_IFELSE(
23             [AC_LANG_SOURCE([[
24 #ifndef __NO_MATH_INLINES
25 # define __NO_MATH_INLINES 1 /* for glibc */
26 #endif
27 #include <math.h>
28 ]gl_DOUBLE_MINUS_ZERO_CODE[
29 ]gl_DOUBLE_SIGNBIT_CODE[
30 /* Compare two numbers with ==.
31    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
32    'x == x' test.  */
33 static int
34 numeric_equal (double x, double y)
35 {
36   return x == y;
37 }
38 static double dummy (double x, double y) { return 0; }
39 int main (int argc, char *argv[])
40 {
41   double (*my_fmod) (double, double) = argc ? fmod : dummy;
42   int result = 0;
43   double f;
44   /* Test fmod(...,0.0).
45      This test fails on OSF/1 5.1.  */
46   f = my_fmod (2.0, 0.0);
47   if (numeric_equal (f, f))
48     result |= 1;
49   /* Test fmod(-0.0,...).
50      This test fails on native Windows.  */
51   f = my_fmod (minus_zerod, 2.0);
52   if (!(f == 0.0) || (signbitd (minus_zerod) && !signbitd (f)))
53     result |= 2;
54   return result;
55 }
56             ]])],
57             [gl_cv_func_fmod_ieee=yes],
58             [gl_cv_func_fmod_ieee=no],
59             [gl_cv_func_fmod_ieee="guessing no"])
60           LIBS="$save_LIBS"
61         ])
62       case "$gl_cv_func_fmod_ieee" in
63         *yes) ;;
64         *) REPLACE_FMOD=1 ;;
65       esac
66     fi
67   ])
68   if test $REPLACE_FMOD = 1; then
69     dnl Find libraries needed to link lib/fmod.c.
70     AC_REQUIRE([gl_FUNC_FABS])
71     AC_REQUIRE([gl_FUNC_FREXP])
72     AC_REQUIRE([gl_FUNC_TRUNC])
73     AC_REQUIRE([gl_FUNC_LDEXP])
74     AC_REQUIRE([gl_FUNC_ISNAND])
75     FMOD_LIBM=
76     dnl Append $FABS_LIBM to FMOD_LIBM, avoiding gratuitous duplicates.
77     case " $FMOD_LIBM " in
78       *" $FABS_LIBM "*) ;;
79       *) FMOD_LIBM="$FMOD_LIBM $FABS_LIBM" ;;
80     esac
81     dnl Append $FREXP_LIBM to FMOD_LIBM, avoiding gratuitous duplicates.
82     case " $FMOD_LIBM " in
83       *" $FREXP_LIBM "*) ;;
84       *) FMOD_LIBM="$FMOD_LIBM $FREXP_LIBM" ;;
85     esac
86     dnl Append $TRUNC_LIBM to FMOD_LIBM, avoiding gratuitous duplicates.
87     case " $FMOD_LIBM " in
88       *" $TRUNC_LIBM "*) ;;
89       *) FMOD_LIBM="$FMOD_LIBM $TRUNC_LIBM" ;;
90     esac
91     dnl Append $LDEXP_LIBM to FMOD_LIBM, avoiding gratuitous duplicates.
92     case " $FMOD_LIBM " in
93       *" $LDEXP_LIBM "*) ;;
94       *) FMOD_LIBM="$FMOD_LIBM $LDEXP_LIBM" ;;
95     esac
96     dnl Append $ISNAND_LIBM to FMOD_LIBM, avoiding gratuitous duplicates.
97     case " $FMOD_LIBM " in
98       *" $ISNAND_LIBM "*) ;;
99       *) FMOD_LIBM="$FMOD_LIBM $ISNAND_LIBM" ;;
100     esac
101   fi
102 ])