Add script for determining the set of symbols to export from a library.
[gnulib.git] / m4 / hypotf.m4
blob80da9aeae6b5abc05af9f477c749e668433ed833
1 # hypotf.m4 serial 8
2 dnl Copyright (C) 2012-2019 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_HYPOTF],
9   m4_divert_text([DEFAULTS], [gl_hypotf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_HYPOT])
13   dnl Persuade glibc <math.h> to declare hypotf().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16   dnl Test whether hypotf() exists. Assume that hypotf(), if it exists, is
17   dnl defined in the same library as hypot().
18   save_LIBS="$LIBS"
19   LIBS="$LIBS $HYPOT_LIBM"
20   AC_CHECK_FUNCS([hypotf])
21   LIBS="$save_LIBS"
22   if test $ac_cv_func_hypotf = yes; then
23     HYPOTF_LIBM="$HYPOT_LIBM"
25     save_LIBS="$LIBS"
26     LIBS="$LIBS $HYPOTF_LIBM"
27     gl_FUNC_HYPOTF_WORKS
28     LIBS="$save_LIBS"
29     case "$gl_cv_func_hypotf_works" in
30       *yes) ;;
31       *) REPLACE_HYPOTF=1 ;;
32     esac
34     m4_ifdef([gl_FUNC_HYPOTF_IEEE], [
35       if test $gl_hypotf_required = ieee && test $REPLACE_HYPOTF = 0; then
36         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
37         AC_CACHE_CHECK([whether hypotf works according to ISO C 99 with IEC 60559],
38           [gl_cv_func_hypotf_ieee],
39           [
40             save_LIBS="$LIBS"
41             LIBS="$LIBS $HYPOTF_LIBM"
42             AC_RUN_IFELSE(
43               [AC_LANG_SOURCE([[
44 #ifndef __NO_MATH_INLINES
45 # define __NO_MATH_INLINES 1 /* for glibc */
46 #endif
47 #include <math.h>
48 /* Compare two numbers with ==.
49    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
50    'x == x' test.  */
51 static int
52 numeric_equal (float x, float y)
54   return x == y;
56 static float dummy (float x, float y) { return 0; }
57 float zero;
58 float one = 1.0f;
59 int main (int argc, char *argv[])
61   float (* volatile my_hypotf) (float, float) = argc ? hypotf : dummy;
62   float f;
63   /* Test hypotf(NaN,Infinity).
64      This test fails on OSF/1 5.1 and native Windows.  */
65   f = my_hypotf (zero / zero, one / zero);
66   if (!numeric_equal (f, f))
67     return 1;
68   return 0;
70               ]])],
71               [gl_cv_func_hypotf_ieee=yes],
72               [gl_cv_func_hypotf_ieee=no],
73               [case "$host_os" in
74                                 # Guess yes on glibc systems.
75                  *-gnu* | gnu*) gl_cv_func_hypotf_ieee="guessing yes" ;;
76                                 # Guess yes on native Windows.
77                  mingw*)        gl_cv_func_hypotf_ieee="guessing yes" ;;
78                                 # If we don't know, assume the worst.
79                  *)             gl_cv_func_hypotf_ieee="guessing no" ;;
80                esac
81               ])
82             LIBS="$save_LIBS"
83           ])
84         case "$gl_cv_func_hypotf_ieee" in
85           *yes) ;;
86           *) REPLACE_HYPOTF=1 ;;
87         esac
88       fi
89     ])
90   else
91     HAVE_HYPOTF=0
92     dnl If the function is declared but does not appear to exist, it may be
93     dnl defined as an inline function. In order to avoid a conflict, we have
94     dnl to define rpl_hypotf, not hypotf.
95     AC_CHECK_DECLS([hypotf], [REPLACE_HYPOTF=1], , [[#include <math.h>]])
96   fi
97   if test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1; then
98     dnl Find libraries needed to link lib/hypotf.c.
99     HYPOTF_LIBM="$HYPOT_LIBM"
100   fi
101   AC_SUBST([HYPOTF_LIBM])
104 dnl Test whether hypotf() works.
105 dnl It returns wrong values on NetBSD 5.1/x86_64 and OpenBSD 4.9/x86.
106 AC_DEFUN([gl_FUNC_HYPOTF_WORKS],
108   AC_REQUIRE([AC_PROG_CC])
109   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
110   AC_CACHE_CHECK([whether hypotf works], [gl_cv_func_hypotf_works],
111     [
112       AC_RUN_IFELSE(
113         [AC_LANG_SOURCE([[
114 #include <float.h>
115 #include <math.h>
116 volatile float x;
117 volatile float y;
118 volatile float z;
119 int main ()
121   int result = 0;
122   /* This test fails on NetBSD 5.1.  */
123   {
124     x = FLT_MIN * 2.0f;
125     y = FLT_MIN * 3.0f;
126     z = hypotf (x, y);
127     if (!(z >= FLT_MIN * 2.0f && z <= FLT_MIN * 4.0f))
128       result |= 1;
129   }
130   /* This test fails on OpenBSD 4.9.  */
131   {
132     x = FLT_MAX;
133     y = FLT_MAX * 0.5f;
134     z = hypotf (x, y);
135     if (!(z > 0 && z == z + z))
136       result |= 2;
137   }
138   return result;
140 ]])],
141         [gl_cv_func_hypotf_works=yes],
142         [gl_cv_func_hypotf_works=no],
143         [case "$host_os" in
144            netbsd* | openbsd*) gl_cv_func_hypotf_works="guessing no" ;;
145                                # Guess yes on native Windows.
146            mingw*)             gl_cv_func_hypotf_works="guessing yes" ;;
147            *)                  gl_cv_func_hypotf_works="guessing yes" ;;
148          esac
149         ])
150     ])