maint.mk: avoid spurious failure of _sc_search_regexp-using tests
[gnulib.git] / m4 / hypotf.m4
1 # hypotf.m4 serial 2
2 dnl Copyright (C) 2012 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.
6
7 AC_DEFUN([gl_FUNC_HYPOTF],
8 [
9   m4_divert_text([DEFAULTS], [gl_hypotf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_HYPOT])
12
13   dnl Test whether hypotf() exists. Assume that hypotf(), if it exists, is
14   dnl defined in the same library as hypot().
15   save_LIBS="$LIBS"
16   LIBS="$LIBS $HYPOT_LIBM"
17   AC_CHECK_FUNCS([hypotf])
18   LIBS="$save_LIBS"
19   if test $ac_cv_func_hypotf = yes; then
20     HYPOTF_LIBM="$HYPOT_LIBM"
21     save_LIBS="$LIBS"
22     LIBS="$LIBS $HYPOTF_LIBM"
23     gl_FUNC_HYPOTF_WORKS
24     LIBS="$save_LIBS"
25     case "$gl_cv_func_hypotf_works" in
26       *yes) ;;
27       *) REPLACE_HYPOTF=1 ;;
28     esac
29     m4_ifdef([gl_FUNC_HYPOTF_IEEE], [
30       if test $gl_hypotf_required = ieee && test $REPLACE_HYPOTF = 0; then
31         AC_CACHE_CHECK([whether hypotf works according to ISO C 99 with IEC 60559],
32           [gl_cv_func_hypotf_ieee],
33           [
34             save_LIBS="$LIBS"
35             LIBS="$LIBS $HYPOTF_LIBM"
36             AC_RUN_IFELSE(
37               [AC_LANG_SOURCE([[
38 #ifndef __NO_MATH_INLINES
39 # define __NO_MATH_INLINES 1 /* for glibc */
40 #endif
41 #include <math.h>
42 /* Compare two numbers with ==.
43    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
44    'x == x' test.  */
45 static int
46 numeric_equal (float x, float y)
47 {
48   return x == y;
49 }
50 static float dummy (float x, float y) { return 0; }
51 float zero;
52 float one = 1.0f;
53 int main (int argc, char *argv[])
54 {
55   float (*my_hypotf) (float, float) = argc ? hypotf : dummy;
56   float f;
57   /* Test hypotf(NaN,Infinity).
58      This test fails on OSF/1 5.1 and native Windows.  */
59   f = my_hypotf (zero / zero, one / zero);
60   if (!numeric_equal (f, f))
61     return 1;
62   return 0;
63 }
64               ]])],
65               [gl_cv_func_hypotf_ieee=yes],
66               [gl_cv_func_hypotf_ieee=no],
67               [gl_cv_func_hypotf_ieee="guessing no"])
68             LIBS="$save_LIBS"
69           ])
70         case "$gl_cv_func_hypotf_ieee" in
71           *yes) ;;
72           *) REPLACE_HYPOTF=1 ;;
73         esac
74       fi
75     ])
76   else
77     HAVE_HYPOTF=0
78   fi
79   if test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1; then
80     dnl Find libraries needed to link lib/hypotf.c.
81     HYPOTF_LIBM="$HYPOT_LIBM"
82   fi
83   AC_SUBST([HYPOTF_LIBM])
84 ])
85
86 dnl Test whether hypotf() works.
87 dnl It returns wrong values on NetBSD 5.1/x86_64 and OpenBSD 4.9/x86.
88 AC_DEFUN([gl_FUNC_HYPOTF_WORKS],
89 [
90   AC_REQUIRE([AC_PROG_CC])
91   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
92   AC_CACHE_CHECK([whether hypotf works], [gl_cv_func_hypotf_works],
93     [
94       AC_RUN_IFELSE(
95         [AC_LANG_SOURCE([[
96 #include <float.h>
97 #include <math.h>
98 volatile float x;
99 volatile float y;
100 volatile float z;
101 int main ()
102 {
103   int result = 0;
104   /* This test fails on NetBSD 5.1.  */
105   {
106     x = FLT_MIN * 2.0f;
107     y = FLT_MIN * 3.0f;
108     z = hypotf (x, y);
109     if (!(z >= FLT_MIN * 2.0f && z <= FLT_MIN * 4.0f))
110       result |= 1;
111   }
112   /* This test fails on OpenBSD 4.9.  */
113   {
114     x = FLT_MAX;
115     y = FLT_MAX * 0.5f;
116     z = hypotf (x, y);
117     if (!(z > 0 && z == z + z))
118       result |= 2;
119   }
120   return result;
121 }
122 ]])],
123         [gl_cv_func_hypotf_works=yes],
124         [gl_cv_func_hypotf_works=no],
125         [case "$host_os" in
126            netbsd* | openbsd*) gl_cv_func_hypotf_works="guessing no";;
127            *)                  gl_cv_func_hypotf_works="guessing yes";;
128          esac
129         ])
130     ])
131 ])