Debian Codegraph @

m4/modfl.m4

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