immutable: Add tests.
[gnulib.git] / m4 / modfl.m4
blob7f4b6d2fb8344a7dcee8f8408ced1949ac3f0081
1 # modfl.m4 serial 8
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_MODFL],
9   m4_divert_text([DEFAULTS], [gl_modfl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
13   dnl Persuade glibc <math.h> to declare modfl().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16   dnl Test whether modfl() exists. We cannot assume that modfl(), if it
17   dnl exists, is defined in the same library as modf(). This is not the case
18   dnl on FreeBSD, Solaris.
19   gl_MATHFUNC([modfl], [long double], [(long double, long double *)])
20   if test $gl_cv_func_modfl_no_libm = yes \
21      || test $gl_cv_func_modfl_in_libm = yes; then
22     :
23     m4_ifdef([gl_FUNC_MODFL_IEEE], [
24       if test $gl_modfl_required = ieee && test $REPLACE_MODFL = 0; then
25         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
26         AC_CACHE_CHECK([whether modfl works according to ISO C 99 with IEC 60559],
27           [gl_cv_func_modfl_ieee],
28           [
29             save_LIBS="$LIBS"
30             LIBS="$LIBS $MODFL_LIBM"
31             AC_RUN_IFELSE(
32               [AC_LANG_SOURCE([[
33 #ifndef __NO_MATH_INLINES
34 # define __NO_MATH_INLINES 1 /* for glibc */
35 #endif
36 #include <math.h>
37 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
38 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
39 /* Compare two numbers with ==.
40    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
41    'x == x' test.  */
42 static int
43 numeric_equal (long double x, long double y)
45   return x == y;
47 static long double dummy (long double x, long double *iptr) { return 0; }
48 long double zero;
49 long double minus_one = - 1.0L;
50 int main (int argc, char *argv[])
52   long double (* volatile my_modfl) (long double, long double *) = argc ? modfl : dummy;
53   long double i;
54   long double f;
55   /* Test modfl(-Inf,...).
56      This test fails on IRIX 6.5, OSF/1 5.1, mingw.  */
57   f = my_modfl (minus_one / zero, &i);
58   if (!(f == 0.0L) || (signbitl (minus_zerol) && !signbitl (f)))
59     return 1;
60   return 0;
62               ]])],
63               [gl_cv_func_modfl_ieee=yes],
64               [gl_cv_func_modfl_ieee=no],
65               [case "$host_os" in
66                                 # Guess yes on glibc systems.
67                  *-gnu* | gnu*) gl_cv_func_modfl_ieee="guessing yes" ;;
68                                 # Guess yes on musl systems.
69                  *-musl*)       gl_cv_func_modfl_ieee="guessing yes" ;;
70                                 # Guess yes on MSVC, no on mingw.
71                  mingw*)        AC_EGREP_CPP([Known], [
72 #ifdef _MSC_VER
73  Known
74 #endif
75                                   ],
76                                   [gl_cv_func_modfl_ieee="guessing yes"],
77                                   [gl_cv_func_modfl_ieee="guessing no"])
78                                 ;;
79                                 # If we don't know, obey --enable-cross-guesses.
80                  *)             gl_cv_func_modfl_ieee="$gl_cross_guess_normal" ;;
81                esac
82               ])
83             LIBS="$save_LIBS"
84           ])
85         case "$gl_cv_func_modfl_ieee" in
86           *yes) ;;
87           *) REPLACE_MODFL=1 ;;
88         esac
89       fi
90     ])
91   else
92     HAVE_MODFL=0
93   fi
94   if test $HAVE_MODFL = 0 || test $REPLACE_MODFL = 1; then
95     dnl Find libraries needed to link lib/modfl.c.
96     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
97       AC_REQUIRE([gl_FUNC_MODF])
98       MODFL_LIBM="$MODF_LIBM"
99     else
100       AC_REQUIRE([gl_FUNC_TRUNCL])
101       MODFL_LIBM="$TRUNCL_LIBM"
102     fi
103   fi
104   AC_SUBST([MODFL_LIBM])