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