verify: new macro 'assume'
[gnulib.git] / m4 / hypotf.m4
1 # hypotf.m4 serial 4
2 dnl Copyright (C) 2012-2013 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 Persuade glibc <math.h> to declare hypotf().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
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"
24     save_LIBS="$LIBS"
25     LIBS="$LIBS $HYPOTF_LIBM"
26     gl_FUNC_HYPOTF_WORKS
27     LIBS="$save_LIBS"
28     case "$gl_cv_func_hypotf_works" in
29       *yes) ;;
30       *) REPLACE_HYPOTF=1 ;;
31     esac
32     m4_ifdef([gl_FUNC_HYPOTF_IEEE], [
33       if test $gl_hypotf_required = ieee && test $REPLACE_HYPOTF = 0; then
34         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
35         AC_CACHE_CHECK([whether hypotf works according to ISO C 99 with IEC 60559],
36           [gl_cv_func_hypotf_ieee],
37           [
38             save_LIBS="$LIBS"
39             LIBS="$LIBS $HYPOTF_LIBM"
40             AC_RUN_IFELSE(
41               [AC_LANG_SOURCE([[
42 #ifndef __NO_MATH_INLINES
43 # define __NO_MATH_INLINES 1 /* for glibc */
44 #endif
45 #include <math.h>
46 /* Compare two numbers with ==.
47    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
48    'x == x' test.  */
49 static int
50 numeric_equal (float x, float y)
51 {
52   return x == y;
53 }
54 static float dummy (float x, float y) { return 0; }
55 float zero;
56 float one = 1.0f;
57 int main (int argc, char *argv[])
58 {
59   float (*my_hypotf) (float, float) = argc ? hypotf : dummy;
60   float f;
61   /* Test hypotf(NaN,Infinity).
62      This test fails on OSF/1 5.1 and native Windows.  */
63   f = my_hypotf (zero / zero, one / zero);
64   if (!numeric_equal (f, f))
65     return 1;
66   return 0;
67 }
68               ]])],
69               [gl_cv_func_hypotf_ieee=yes],
70               [gl_cv_func_hypotf_ieee=no],
71               [case "$host_os" in
72                          # Guess yes on glibc systems.
73                  *-gnu*) gl_cv_func_hypotf_ieee="guessing yes" ;;
74                          # If we don't know, assume the worst.
75                  *)      gl_cv_func_hypotf_ieee="guessing no" ;;
76                esac
77               ])
78             LIBS="$save_LIBS"
79           ])
80         case "$gl_cv_func_hypotf_ieee" in
81           *yes) ;;
82           *) REPLACE_HYPOTF=1 ;;
83         esac
84       fi
85     ])
86   else
87     HAVE_HYPOTF=0
88   fi
89   if test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1; then
90     dnl Find libraries needed to link lib/hypotf.c.
91     HYPOTF_LIBM="$HYPOT_LIBM"
92   fi
93   AC_SUBST([HYPOTF_LIBM])
94 ])
95
96 dnl Test whether hypotf() works.
97 dnl It returns wrong values on NetBSD 5.1/x86_64 and OpenBSD 4.9/x86.
98 AC_DEFUN([gl_FUNC_HYPOTF_WORKS],
99 [
100   AC_REQUIRE([AC_PROG_CC])
101   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
102   AC_CACHE_CHECK([whether hypotf works], [gl_cv_func_hypotf_works],
103     [
104       AC_RUN_IFELSE(
105         [AC_LANG_SOURCE([[
106 #include <float.h>
107 #include <math.h>
108 volatile float x;
109 volatile float y;
110 volatile float z;
111 int main ()
112 {
113   int result = 0;
114   /* This test fails on NetBSD 5.1.  */
115   {
116     x = FLT_MIN * 2.0f;
117     y = FLT_MIN * 3.0f;
118     z = hypotf (x, y);
119     if (!(z >= FLT_MIN * 2.0f && z <= FLT_MIN * 4.0f))
120       result |= 1;
121   }
122   /* This test fails on OpenBSD 4.9.  */
123   {
124     x = FLT_MAX;
125     y = FLT_MAX * 0.5f;
126     z = hypotf (x, y);
127     if (!(z > 0 && z == z + z))
128       result |= 2;
129   }
130   return result;
131 }
132 ]])],
133         [gl_cv_func_hypotf_works=yes],
134         [gl_cv_func_hypotf_works=no],
135         [case "$host_os" in
136            netbsd* | openbsd*) gl_cv_func_hypotf_works="guessing no";;
137            *)                  gl_cv_func_hypotf_works="guessing yes";;
138          esac
139         ])
140     ])
141 ])