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],
28 LIBS="$LIBS $MODFL_LIBM"
31 #ifndef __NO_MATH_INLINES
32 # define __NO_MATH_INLINES 1 /* for glibc */
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;
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))
49 [gl_cv_func_modfl_works=yes],
50 [gl_cv_func_modfl_works=no],
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" ;;
64 case "$gl_cv_func_modfl_works" in
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],
75 LIBS="$LIBS $MODFL_LIBM"
78 #ifndef __NO_MATH_INLINES
79 # define __NO_MATH_INLINES 1 /* for glibc */
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
88 numeric_equal (long double x, long double y)
92 static long double dummy (long double x, long double *iptr) { return 0; }
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;
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)))
108 [gl_cv_func_modfl_ieee=yes],
109 [gl_cv_func_modfl_ieee=no],
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], [
122 [gl_cv_func_modfl_ieee="guessing yes"],
123 [gl_cv_func_modfl_ieee="guessing no"])
125 # If we don't know, obey --enable-cross-guesses.
126 *) gl_cv_func_modfl_ieee="$gl_cross_guess_normal" ;;
131 case "$gl_cv_func_modfl_ieee" in
133 *) REPLACE_MODFL=1 ;;
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"
146 AC_REQUIRE([gl_FUNC_TRUNCL])
147 MODFL_LIBM="$TRUNCL_LIBM"
150 AC_SUBST([MODFL_LIBM])