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_MODFF],
9 m4_divert_text([DEFAULTS], [gl_modff_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_FUNC_MODF])
13 dnl Persuade glibc <math.h> to declare modff().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 dnl Test whether modff() exists. We cannot assume that modff(), if it
17 dnl exists, is defined in the same library as modf(). This is not the case
18 dnl on FreeBSD, NetBSD, OpenBSD.
19 gl_MATHFUNC([modff], [float], [(float, float *)])
20 if test $gl_cv_func_modff_no_libm = yes \
21 || test $gl_cv_func_modff_in_libm = yes; then
23 m4_ifdef([gl_FUNC_MODFF_IEEE], [
24 if test $gl_modff_required = ieee && test $REPLACE_MODFF = 0; then
25 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
26 AC_CACHE_CHECK([whether modff works according to ISO C 99 with IEC 60559],
27 [gl_cv_func_modff_ieee],
30 LIBS="$LIBS $MODFF_LIBM"
33 #ifndef __NO_MATH_INLINES
34 # define __NO_MATH_INLINES 1 /* for glibc */
37 ]gl_FLOAT_MINUS_ZERO_CODE[
38 ]gl_FLOAT_SIGNBIT_CODE[
39 /* Compare two numbers with ==.
40 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
43 numeric_equal (float x, float y)
47 static float dummy (float x, float *iptr) { return 0; }
49 float minus_one = - 1.0f;
50 int main (int argc, char *argv[])
52 float (* volatile my_modff) (float, float *) = argc ? modff : dummy;
56 /* Test modff(NaN,...).
57 This test fails on NetBSD 5.1, OpenBSD 6.7, Solaris 9, Cygwin. */
58 f = my_modff (zero / zero, &i);
59 if (numeric_equal (f, f))
61 /* Test modff(-Inf,...).
62 This test fails on IRIX 6.5, OSF/1 5.1, mingw. */
63 f = my_modff (minus_one / zero, &i);
64 if (!(f == 0.0f) || (signbitf (minus_zerof) && !signbitf (f)))
69 [gl_cv_func_modff_ieee=yes],
70 [gl_cv_func_modff_ieee=no],
72 # Guess yes on glibc systems.
73 *-gnu* | gnu*) gl_cv_func_modff_ieee="guessing yes" ;;
74 # Guess yes on musl systems.
75 *-musl*) gl_cv_func_modff_ieee="guessing yes" ;;
76 # Guess yes on MSVC, no on mingw.
77 mingw*) AC_EGREP_CPP([Known], [
82 [gl_cv_func_modff_ieee="guessing yes"],
83 [gl_cv_func_modff_ieee="guessing no"])
85 # If we don't know, obey --enable-cross-guesses.
86 *) gl_cv_func_modff_ieee="$gl_cross_guess_normal" ;;
91 case "$gl_cv_func_modff_ieee" in
100 if test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1; then
101 dnl Find libraries needed to link lib/modff.c.
102 MODFF_LIBM="$MODF_LIBM"
104 AC_SUBST([MODFF_LIBM])