havelib: Fix for Solaris 11 OpenIndiana and Solaris 11 OmniOS.
[gnulib.git] / m4 / fmodf.m4
blob2cfb2382a6a99ee5bdb28e3ab741ce297abc4054
1 # fmodf.m4 serial 11
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_FMODF],
9   m4_divert_text([DEFAULTS], [gl_fmodf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_FMOD])
13   dnl Persuade glibc <math.h> to declare fmodf().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16   dnl Test whether fmodf() exists. Assume that fmodf(), if it exists, is
17   dnl defined in the same library as fmod().
18   save_LIBS="$LIBS"
19   LIBS="$LIBS $FMOD_LIBM"
20   AC_CHECK_FUNCS([fmodf])
21   LIBS="$save_LIBS"
22   if test $ac_cv_func_fmodf = yes; then
23     FMODF_LIBM="$FMOD_LIBM"
24     m4_ifdef([gl_FUNC_FMODF_IEEE], [
25       if test $gl_fmodf_required = ieee && test $REPLACE_FMODF = 0; then
26         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
27         AC_CACHE_CHECK([whether fmodf works according to ISO C 99 with IEC 60559],
28           [gl_cv_func_fmodf_ieee],
29           [
30             save_LIBS="$LIBS"
31             LIBS="$LIBS $FMODF_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 /* Compare two numbers with ==.
39    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
40    'x == x' test.  */
41 static int
42 numeric_equal (float x, float y)
44   return x == y;
46 static float dummy (float x, float y) { return 0; }
47 int main (int argc, char *argv[])
49   float (* volatile my_fmodf) (float, float) = argc ? fmodf : dummy;
50   float f;
51   /* Test fmodf(...,0.0f).
52      This test fails on OSF/1 5.1.  */
53   f = my_fmodf (2.0f, 0.0f);
54   if (numeric_equal (f, f))
55     return 1;
56   return 0;
58               ]])],
59               [gl_cv_func_fmodf_ieee=yes],
60               [gl_cv_func_fmodf_ieee=no],
61               [case "$host_os" in
62                                 # Guess yes on glibc systems.
63                  *-gnu* | gnu*) gl_cv_func_fmodf_ieee="guessing yes" ;;
64                                 # Guess yes on musl systems.
65                  *-musl*)       gl_cv_func_fmodf_ieee="guessing yes" ;;
66                                 # Guess yes on native Windows.
67                  mingw*)        gl_cv_func_fmodf_ieee="guessing yes" ;;
68                                 # If we don't know, obey --enable-cross-guesses.
69                  *)             gl_cv_func_fmodf_ieee="$gl_cross_guess_normal" ;;
70                esac
71               ])
72             LIBS="$save_LIBS"
73           ])
74         case "$gl_cv_func_fmodf_ieee" in
75           *yes) ;;
76           *) REPLACE_FMODF=1 ;;
77         esac
78       fi
79     ])
80   else
81     HAVE_FMODF=0
82     dnl If the function is declared but does not appear to exist, it may be
83     dnl defined as an inline function. In order to avoid a conflict, we have
84     dnl to define rpl_fmodf, not fmodf.
85     AC_CHECK_DECLS([fmodf], [REPLACE_FMODF=1], , [[#include <math.h>]])
86   fi
87   if test $HAVE_FMODF = 0 || test $REPLACE_FMODF = 1; then
88     dnl Find libraries needed to link lib/fmodf.c.
89     FMODF_LIBM="$FMOD_LIBM"
90   fi
91   AC_SUBST([FMODF_LIBM])