doc: Mention the byteswap module in function documentation.
[gnulib.git] / m4 / modfl.m4
blob12475b897d1672ed81ba014567cd89c1438c455a
1 # modfl.m4
2 # serial 14
3 dnl Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_MODFL],
10   m4_divert_text([DEFAULTS], [gl_modfl_required=plain])
11   AC_REQUIRE([gl_MATH_H_DEFAULTS])
12   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
14   dnl Persuade glibc <math.h> to declare modfl().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17   dnl Test whether modfl() exists. We cannot assume that modfl(), if it
18   dnl exists, is defined in the same library as modf(). This is not the case
19   dnl on FreeBSD, Solaris.
20   gl_MATHFUNC([modfl], [long double], [(long double, long double *)])
21   if test $gl_cv_func_modfl_no_libm = yes \
22      || test $gl_cv_func_modfl_in_libm = yes; then
23     AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
24     AC_CACHE_CHECK([whether modfl works],
25       [gl_cv_func_modfl_works],
26       [
27         saved_LIBS="$LIBS"
28         LIBS="$LIBS $MODFL_LIBM"
29         AC_RUN_IFELSE(
30           [AC_LANG_SOURCE([[
31 #ifndef __NO_MATH_INLINES
32 # define __NO_MATH_INLINES 1 /* for glibc */
33 #endif
34 #include <math.h>
35 static long double dummy (long double x, long double *iptr) { return 0; }
36 int main (int argc, char *argv[])
38   long double (* volatile my_modfl) (long double, long double *) = argc ? modfl : dummy;
39   long double i;
40   long double f;
41   /* Test modfl(5.972406760L,...).
42      This test fails on NetBSD 10.0/arm64.  */
43   f = my_modfl (5.972406760L, &i);
44   if (!(f < 1.0L && i == 5.0L))
45     return 1;
46   return 0;
48           ]])],
49           [gl_cv_func_modfl_works=yes],
50           [gl_cv_func_modfl_works=no],
51           [case "$host_os" in
52                                  # Guess yes on glibc systems.
53              *-gnu* | gnu*)      gl_cv_func_modfl_works="guessing yes" ;;
54                                  # Guess yes on musl systems.
55              *-musl* | midipix*) gl_cv_func_modfl_works="guessing yes" ;;
56                                  # Guess yes on native Windows.
57              mingw* | windows*)  gl_cv_func_modfl_works="guessing yes" ;;
58                                  # If we don't know, obey --enable-cross-guesses.
59              *)                  gl_cv_func_modfl_works="$gl_cross_guess_normal" ;;
60            esac
61           ])
62         LIBS="$saved_LIBS"
63       ])
64     case "$gl_cv_func_modfl_works" in
65       *yes) ;;
66       *) REPLACE_MODFL=1 ;;
67     esac
68     m4_ifdef([gl_FUNC_MODFL_IEEE], [
69       if test $gl_modfl_required = ieee && test $REPLACE_MODFL = 0; then
70         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
71         AC_CACHE_CHECK([whether modfl works according to ISO C 99 with IEC 60559],
72           [gl_cv_func_modfl_ieee],
73           [
74             saved_LIBS="$LIBS"
75             LIBS="$LIBS $MODFL_LIBM"
76             AC_RUN_IFELSE(
77               [AC_LANG_SOURCE([[
78 #ifndef __NO_MATH_INLINES
79 # define __NO_MATH_INLINES 1 /* for glibc */
80 #endif
81 #include <math.h>
82 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
83 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
84 /* Compare two numbers with ==.
85    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
86    'x == x' test.  */
87 static int
88 numeric_equal (long double x, long double y)
90   return x == y;
92 static long double dummy (long double x, long double *iptr) { return 0; }
93 long double zero;
94 long double minus_one = - 1.0L;
95 int main (int argc, char *argv[])
97   long double (* volatile my_modfl) (long double, long double *) = argc ? modfl : dummy;
98   long double i;
99   long double f;
100   /* Test modfl(-Inf,...).
101      This test fails on IRIX 6.5, OSF/1 5.1, mingw.  */
102   f = my_modfl (minus_one / zero, &i);
103   if (!(f == 0.0L) || (signbitl (minus_zerol) && !signbitl (f)))
104     return 1;
105   return 0;
107               ]])],
108               [gl_cv_func_modfl_ieee=yes],
109               [gl_cv_func_modfl_ieee=no],
110               [case "$host_os" in
111                                      # Guess yes on glibc systems.
112                  *-gnu* | gnu*)      gl_cv_func_modfl_ieee="guessing yes" ;;
113                                      # Guess yes on musl systems.
114                  *-musl* | midipix*) gl_cv_func_modfl_ieee="guessing yes" ;;
115                                      # Guess yes on MSVC, no on mingw.
116                  windows*-msvc*)     gl_cv_func_modfl_ieee="guessing yes" ;;
117                  mingw* | windows*)  AC_EGREP_CPP([Known], [
118 #ifdef _MSC_VER
119  Known
120 #endif
121                                        ],
122                                        [gl_cv_func_modfl_ieee="guessing yes"],
123                                        [gl_cv_func_modfl_ieee="guessing no"])
124                                      ;;
125                                      # If we don't know, obey --enable-cross-guesses.
126                  *)                  gl_cv_func_modfl_ieee="$gl_cross_guess_normal" ;;
127                esac
128               ])
129             LIBS="$saved_LIBS"
130           ])
131         case "$gl_cv_func_modfl_ieee" in
132           *yes) ;;
133           *) REPLACE_MODFL=1 ;;
134         esac
135       fi
136     ])
137   else
138     HAVE_MODFL=0
139   fi
140   if test $HAVE_MODFL = 0 || test $REPLACE_MODFL = 1; then
141     dnl Find libraries needed to link lib/modfl.c.
142     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
143       AC_REQUIRE([gl_FUNC_MODF])
144       MODFL_LIBM="$MODF_LIBM"
145     else
146       AC_REQUIRE([gl_FUNC_TRUNCL])
147       MODFL_LIBM="$TRUNCL_LIBM"
148     fi
149   fi
150   AC_SUBST([MODFL_LIBM])