New module 'hypotf'.
[gnulib.git] / m4 / hypotf.m4
1 # hypotf.m4 serial 1
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   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_FUNC_HYPOT])
11
12   dnl Test whether hypotf() exists. Assume that hypotf(), if it exists, is
13   dnl defined in the same library as fmod().
14   save_LIBS="$LIBS"
15   LIBS="$LIBS $HYPOT_LIBM"
16   AC_CHECK_FUNCS([hypotf])
17   LIBS="$save_LIBS"
18   if test $ac_cv_func_hypotf = yes; then
19     HYPOTF_LIBM="$HYPOT_LIBM"
20     save_LIBS="$LIBS"
21     LIBS="$LIBS $HYPOTF_LIBM"
22     gl_FUNC_HYPOTF_WORKS
23     LIBS="$save_LIBS"
24     case "$gl_cv_func_hypotf_works" in
25       *yes) ;;
26       *) REPLACE_HYPOTF=1 ;;
27     esac
28   else
29     HAVE_HYPOTF=0
30   fi
31   if test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1; then
32     dnl Find libraries needed to link lib/hypotf.c.
33     HYPOTF_LIBM="$HYPOT_LIBM"
34   fi
35   AC_SUBST([HYPOTF_LIBM])
36 ])
37
38 dnl Test whether hypotf() works.
39 dnl It returns wrong values on NetBSD 5.1/x86_64 and OpenBSD 4.9/x86.
40 AC_DEFUN([gl_FUNC_HYPOTF_WORKS],
41 [
42   AC_REQUIRE([AC_PROG_CC])
43   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
44   AC_CACHE_CHECK([whether hypotf works], [gl_cv_func_hypotf_works],
45     [
46       AC_RUN_IFELSE(
47         [AC_LANG_SOURCE([[
48 #include <float.h>
49 #include <math.h>
50 volatile float x;
51 volatile float y;
52 volatile float z;
53 int main ()
54 {
55   int result = 0;
56   /* This test fails on NetBSD 5.1.  */
57   {
58     x = FLT_MIN * 2.0f;
59     y = FLT_MIN * 3.0f;
60     z = hypotf (x, y);
61     if (!(z >= FLT_MIN * 2.0f && z <= FLT_MIN * 4.0f))
62       result |= 1;
63   }
64   /* This test fails on OpenBSD 4.9.  */
65   {
66     x = FLT_MAX;
67     y = FLT_MAX * 0.5f;
68     z = hypotf (x, y);
69     if (!(z > 0 && z == z + z))
70       result |= 2;
71   }
72   return result;
73 }
74 ]])],
75         [gl_cv_func_hypotf_works=yes],
76         [gl_cv_func_hypotf_works=no],
77         [case "$host_os" in
78            netbsd* | openbsd*) gl_cv_func_hypotf_works="guessing no";;
79            *)                  gl_cv_func_hypotf_works="guessing yes";;
80          esac
81         ])
82     ])
83 ])