2 dnl Copyright (C) 2011-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_FMODL],
9 m4_divert_text([DEFAULTS], [gl_fmodl_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12 AC_REQUIRE([gl_FUNC_FMOD])
14 dnl Persuade glibc <math.h> to declare fmodl().
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17 dnl Test whether fmodl() is declared.
18 dnl AIX 5.1 has fmodl() in libc but doesn't declare it in <math.h>, and the
19 dnl function produces NaN results for finite values.
20 AC_CHECK_DECL([fmodl],
21 [ac_cv_have_decl_fmodl=yes], [ac_cv_have_decl_fmodl=no],
22 [[#include <math.h>]])
24 dnl Test whether fmodl() exists. Assume that fmodl(), if it exists, is
25 dnl defined in the same library as fmod().
27 LIBS="$LIBS $FMOD_LIBM"
28 AC_CHECK_FUNCS([fmodl])
30 if test $ac_cv_func_fmodl = yes; then
31 FMODL_LIBM="$FMOD_LIBM"
32 if test $ac_cv_have_decl_fmodl = no; then
35 m4_ifdef([gl_FUNC_FMODL_IEEE], [
36 if test $gl_fmodl_required = ieee && test $REPLACE_FMODL = 0; then
37 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
38 AC_CACHE_CHECK([whether fmodl works according to ISO C 99 with IEC 60559],
39 [gl_cv_func_fmodl_ieee],
42 LIBS="$LIBS $FMODL_LIBM"
45 #ifndef __NO_MATH_INLINES
46 # define __NO_MATH_INLINES 1 /* for glibc */
49 /* Compare two numbers with ==.
50 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
53 numeric_equal (long double x, long double y)
57 static long double dummy (long double x, long double y) { return 0; }
58 int main (int argc, char *argv[])
60 long double (* volatile my_fmodl) (long double, long double) = argc ? fmodl : dummy;
62 /* Test fmodl(...,0.0L).
63 This test fails on OSF/1 5.1. */
64 f = my_fmodl (2.0L, 0.0L);
65 if (numeric_equal (f, f))
70 [gl_cv_func_fmodl_ieee=yes],
71 [gl_cv_func_fmodl_ieee=no],
73 # Guess yes on glibc systems.
74 *-gnu* | gnu*) gl_cv_func_fmodl_ieee="guessing yes" ;;
75 # Guess yes on musl systems.
76 *-musl*) gl_cv_func_fmodl_ieee="guessing yes" ;;
77 # Guess yes on native Windows.
78 mingw*) gl_cv_func_fmodl_ieee="guessing yes" ;;
79 # If we don't know, obey --enable-cross-guesses.
80 *) gl_cv_func_fmodl_ieee="$gl_cross_guess_normal" ;;
85 case "$gl_cv_func_fmodl_ieee" in
93 dnl If the function is declared but does not appear to exist, it may be
94 dnl defined as an inline function. In order to avoid a conflict, we have
95 dnl to define rpl_fmodl, not fmodl.
96 AC_CHECK_DECLS([fmodl], [REPLACE_FMODL=1], , [[#include <math.h>]])
98 if test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; then
99 dnl Find libraries needed to link lib/fmodl.c.
100 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
101 FMODL_LIBM="$FMOD_LIBM"
103 AC_REQUIRE([gl_FUNC_FABSL])
104 AC_REQUIRE([gl_FUNC_FREXPL])
105 AC_REQUIRE([gl_FUNC_TRUNCL])
106 AC_REQUIRE([gl_FUNC_LDEXPL])
107 AC_REQUIRE([gl_FUNC_ISNANL])
109 dnl Append $FABSL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
110 case " $FMODL_LIBM " in
111 *" $FABSL_LIBM "*) ;;
112 *) FMODL_LIBM="$FMODL_LIBM $FABSL_LIBM" ;;
114 dnl Append $FREXPL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
115 case " $FMODL_LIBM " in
116 *" $FREXPL_LIBM "*) ;;
117 *) FMODL_LIBM="$FMODL_LIBM $FREXPL_LIBM" ;;
119 dnl Append $TRUNCL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
120 case " $FMODL_LIBM " in
121 *" $TRUNCL_LIBM "*) ;;
122 *) FMODL_LIBM="$FMODL_LIBM $TRUNCL_LIBM" ;;
124 dnl Append $LDEXPL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
125 case " $FMODL_LIBM " in
126 *" $LDEXPL_LIBM "*) ;;
127 *) FMODL_LIBM="$FMODL_LIBM $LDEXPL_LIBM" ;;
129 dnl Append $ISNANL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
130 case " $FMODL_LIBM " in
131 *" $ISNANL_LIBM "*) ;;
132 *) FMODL_LIBM="$FMODL_LIBM $ISNANL_LIBM" ;;
136 AC_SUBST([FMODL_LIBM])