* ChangeLog: Fix misspelling
[gnulib.git] / m4 / modff.m4
blobf58a8eec72810b18ece5939fb71070a3035c1be4
1 # modff.m4
2 # serial 15
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_MODFF],
10   m4_divert_text([DEFAULTS], [gl_modff_required=plain])
11   AC_REQUIRE([gl_MATH_H_DEFAULTS])
12   AC_REQUIRE([gl_FUNC_MODF])
14   dnl Persuade glibc <math.h> to declare modff().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17   dnl Test whether modff() exists. We cannot assume that modff(), if it
18   dnl exists, is defined in the same library as modf(). This is not the case
19   dnl on FreeBSD, NetBSD, OpenBSD.
20   gl_MATHFUNC([modff], [float], [(float, float *)])
21   if test $gl_cv_func_modff_no_libm = yes \
22      || test $gl_cv_func_modff_in_libm = yes; then
23     :
24     m4_ifdef([gl_FUNC_MODFF_IEEE], [
25       if test $gl_modff_required = ieee && test $REPLACE_MODFF = 0; then
26         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
27         AC_CACHE_CHECK([whether modff works according to ISO C 99 with IEC 60559],
28           [gl_cv_func_modff_ieee],
29           [
30             saved_LIBS="$LIBS"
31             LIBS="$LIBS $MODFF_LIBM"
32             AC_RUN_IFELSE(
33               [AC_LANG_SOURCE([[
34 #ifndef __NO_MATH_INLINES
35 # define __NO_MATH_INLINES 1 /* for glibc */
36 #endif
37 #include <math.h>
38 ]gl_FLOAT_MINUS_ZERO_CODE[
39 ]gl_FLOAT_SIGNBIT_CODE[
40 /* Compare two numbers with ==.
41    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
42    'x == x' test.  */
43 static int
44 numeric_equal (float x, float y)
46   return x == y;
48 static float dummy (float x, float *iptr) { return 0; }
49 float zero;
50 float minus_one = - 1.0f;
51 int main (int argc, char *argv[])
53   float (* volatile my_modff) (float, float *) = argc ? modff : dummy;
54   int result = 0;
55   float i;
56   float f;
57   /* Test modff(NaN,...).
58      This test fails on NetBSD 5.1, OpenBSD 6.7, Solaris 9, Cygwin.  */
59   f = my_modff (zero / zero, &i);
60   if (numeric_equal (f, f))
61     result |= 1;
62   /* Test modff(-Inf,...).
63      This test fails on IRIX 6.5, OSF/1 5.1, mingw.  */
64   f = my_modff (minus_one / zero, &i);
65   if (!(f == 0.0f) || (signbitf (minus_zerof) && !signbitf (f)))
66     result |= 2;
67   return result;
69               ]])],
70               [gl_cv_func_modff_ieee=yes],
71               [gl_cv_func_modff_ieee=no],
72               [case "$host_os" in
73                                      # Guess yes on glibc systems.
74                  *-gnu* | gnu*)      gl_cv_func_modff_ieee="guessing yes" ;;
75                                      # Guess yes on musl systems.
76                  *-musl* | midipix*) gl_cv_func_modff_ieee="guessing yes" ;;
77                                      # Guess yes on MSVC, no on mingw.
78                  windows*-msvc*)     gl_cv_func_modff_ieee="guessing yes" ;;
79                  mingw* | windows*)  AC_EGREP_CPP([Known], [
80 #ifdef _MSC_VER
81  Known
82 #endif
83                                        ],
84                                        [gl_cv_func_modff_ieee="guessing yes"],
85                                        [gl_cv_func_modff_ieee="guessing no"])
86                                      ;;
87                                      # If we don't know, obey --enable-cross-guesses.
88                  *)                  gl_cv_func_modff_ieee="$gl_cross_guess_normal" ;;
89                esac
90               ])
91             LIBS="$saved_LIBS"
92           ])
93         case "$gl_cv_func_modff_ieee" in
94           *yes) ;;
95           *) REPLACE_MODFF=1 ;;
96         esac
97       fi
98     ])
99   else
100     HAVE_MODFF=0
101   fi
102   if test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1; then
103     dnl Find libraries needed to link lib/modff.c.
104     MODFF_LIBM="$MODF_LIBM"
105   fi
106   AC_SUBST([MODFF_LIBM])