havelib: Fix for Solaris 11 OpenIndiana and Solaris 11 OmniOS.
[gnulib.git] / m4 / remainder.m4
blob2b013b8f39ae4b4f73bba34fa6d6a218d7e93eb8
1 # remainder.m4 serial 9
2 dnl Copyright (C) 2012-2020 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_REMAINDER],
9   m4_divert_text([DEFAULTS], [gl_remainder_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
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>]])
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_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
60         AC_CACHE_CHECK([whether remainder works according to ISO C 99 with IEC 60559],
61           [gl_cv_func_remainder_ieee],
62           [
63             save_LIBS="$LIBS"
64             LIBS="$LIBS $REMAINDER_LIBM"
65             AC_RUN_IFELSE(
66               [AC_LANG_SOURCE([[
67 #ifndef __NO_MATH_INLINES
68 # define __NO_MATH_INLINES 1 /* for glibc */
69 #endif
70 #include <math.h>
71 /* Compare two numbers with ==.
72    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
73    'x == x' test.  */
74 static int
75 numeric_equal (double x, double y)
77   return x == y;
79 static double dummy (double x, double y) { return 0; }
80 int main (int argc, char *argv[])
82   double (* volatile my_remainder) (double, double) = argc ? remainder : dummy;
83   double f;
84   /* Test remainder(...,0.0).
85      This test fails on OSF/1 5.1.  */
86   f = my_remainder (2.0, 0.0);
87   if (numeric_equal (f, f))
88     return 1;
89   return 0;
91               ]])],
92               [gl_cv_func_remainder_ieee=yes],
93               [gl_cv_func_remainder_ieee=no],
94               [case "$host_os" in
95                                 # Guess yes on glibc systems.
96                  *-gnu* | gnu*) gl_cv_func_remainder_ieee="guessing yes" ;;
97                                 # Guess yes on musl systems.
98                  *-musl*)       gl_cv_func_remainder_ieee="guessing yes" ;;
99                                 # Guess yes on native Windows.
100                  mingw*)        gl_cv_func_remainder_ieee="guessing yes" ;;
101                                 # If we don't know, obey --enable-cross-guesses.
102                  *)             gl_cv_func_remainder_ieee="$gl_cross_guess_normal" ;;
103                esac
104               ])
105             LIBS="$save_LIBS"
106           ])
107         case "$gl_cv_func_remainder_ieee" in
108           *yes) ;;
109           *) REPLACE_REMAINDER=1 ;;
110         esac
111       fi
112     ])
113   else
114     HAVE_REMAINDER=0
115   fi
116   if test $HAVE_REMAINDER = 0 || test $REPLACE_REMAINDER = 1; then
117     dnl Find libraries needed to link lib/remainder.c.
118     AC_REQUIRE([gl_FUNC_FABS])
119     AC_REQUIRE([gl_FUNC_FMOD])
120     AC_REQUIRE([gl_FUNC_ISNAND])
121     REMAINDER_LIBM=
122     dnl Append $FABS_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates.
123     case " $REMAINDER_LIBM " in
124       *" $FABS_LIBM "*) ;;
125       *) REMAINDER_LIBM="$REMAINDER_LIBM $FABS_LIBM" ;;
126     esac
127     dnl Append $FMOD_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates.
128     case " $REMAINDER_LIBM " in
129       *" $FMOD_LIBM "*) ;;
130       *) REMAINDER_LIBM="$REMAINDER_LIBM $FMOD_LIBM" ;;
131     esac
132     dnl Append $ISNAND_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates.
133     case " $REMAINDER_LIBM " in
134       *" $ISNAND_LIBM "*) ;;
135       *) REMAINDER_LIBM="$REMAINDER_LIBM $ISNAND_LIBM" ;;
136     esac
137   fi
138   AC_SUBST([REMAINDER_LIBM])