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_MODF],
9 m4_divert_text([DEFAULTS], [gl_modf_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 dnl Determine MODF_LIBM.
13 gl_MATHFUNC([modf], [double], [(double, double *)])
15 m4_ifdef([gl_FUNC_MODF_IEEE], [
16 if test $gl_modf_required = ieee && test $REPLACE_MODF = 0; then
17 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
18 AC_CACHE_CHECK([whether modf works according to ISO C 99 with IEC 60559],
19 [gl_cv_func_modf_ieee],
22 LIBS="$LIBS $MODF_LIBM"
25 #ifndef __NO_MATH_INLINES
26 # define __NO_MATH_INLINES 1 /* for glibc */
29 ]gl_DOUBLE_MINUS_ZERO_CODE[
30 ]gl_DOUBLE_SIGNBIT_CODE[
31 /* Compare two numbers with ==.
32 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
35 numeric_equal (double x, double y)
39 static double dummy (double x, double *iptr) { return 0; }
41 double minus_one = - 1.0;
42 int main (int argc, char *argv[])
44 double (* volatile my_modf) (double, double *) = argc ? modf : dummy;
48 /* Test modf(NaN,...).
49 This test fails on NetBSD 5.1, Cygwin. */
50 f = my_modf (zero / zero, &i);
51 if (numeric_equal (f, f))
53 /* Test modf(-Inf,...).
54 This test fails on FreeBSD 6.4, OpenBSD 6.7, IRIX 6.5, OSF/1 5.1. */
55 f = my_modf (minus_one / zero, &i);
56 if (!(f == 0.0) || (signbitd (minus_zerod) && !signbitd (f)))
61 [gl_cv_func_modf_ieee=yes],
62 [gl_cv_func_modf_ieee=no],
64 # Guess yes on glibc systems.
65 *-gnu* | gnu*) gl_cv_func_modf_ieee="guessing yes" ;;
66 # Guess yes on musl systems.
67 *-musl*) gl_cv_func_modf_ieee="guessing yes" ;;
68 # Guess yes on MSVC, no on mingw.
69 mingw*) AC_EGREP_CPP([Known], [
74 [gl_cv_func_modf_ieee="guessing yes"],
75 [gl_cv_func_modf_ieee="guessing no"])
77 # If we don't know, obey --enable-cross-guesses.
78 *) gl_cv_func_modf_ieee="$gl_cross_guess_normal" ;;
83 case "$gl_cv_func_modf_ieee" in
89 if test $REPLACE_MODF = 1; then
90 dnl Find libraries needed to link lib/modf.c.
91 AC_REQUIRE([gl_FUNC_TRUNC])
92 MODF_LIBM="$TRUNC_LIBM"