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.
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().
19 LIBS="$LIBS $HYPOT_LIBM"
20 AC_CHECK_FUNCS([hypotf])
22 if test $ac_cv_func_hypotf = yes; then
23 HYPOTF_LIBM="$HYPOT_LIBM"
25 LIBS="$LIBS $HYPOTF_LIBM"
28 case "$gl_cv_func_hypotf_works" in
30 *) REPLACE_HYPOTF=1 ;;
32 m4_ifdef([gl_FUNC_HYPOTF_IEEE], [
33 if test $gl_hypotf_required = ieee && test $REPLACE_HYPOTF = 0; then
34 AC_CACHE_CHECK([whether hypotf works according to ISO C 99 with IEC 60559],
35 [gl_cv_func_hypotf_ieee],
38 LIBS="$LIBS $HYPOTF_LIBM"
41 #ifndef __NO_MATH_INLINES
42 # define __NO_MATH_INLINES 1 /* for glibc */
45 /* Compare two numbers with ==.
46 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
49 numeric_equal (float x, float y)
53 static float dummy (float x, float y) { return 0; }
56 int main (int argc, char *argv[])
58 float (*my_hypotf) (float, float) = argc ? hypotf : dummy;
60 /* Test hypotf(NaN,Infinity).
61 This test fails on OSF/1 5.1 and native Windows. */
62 f = my_hypotf (zero / zero, one / zero);
63 if (!numeric_equal (f, f))
68 [gl_cv_func_hypotf_ieee=yes],
69 [gl_cv_func_hypotf_ieee=no],
70 [gl_cv_func_hypotf_ieee="guessing no"])
73 case "$gl_cv_func_hypotf_ieee" in
75 *) REPLACE_HYPOTF=1 ;;
82 if test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1; then
83 dnl Find libraries needed to link lib/hypotf.c.
84 HYPOTF_LIBM="$HYPOT_LIBM"
86 AC_SUBST([HYPOTF_LIBM])
89 dnl Test whether hypotf() works.
90 dnl It returns wrong values on NetBSD 5.1/x86_64 and OpenBSD 4.9/x86.
91 AC_DEFUN([gl_FUNC_HYPOTF_WORKS],
93 AC_REQUIRE([AC_PROG_CC])
94 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
95 AC_CACHE_CHECK([whether hypotf works], [gl_cv_func_hypotf_works],
107 /* This test fails on NetBSD 5.1. */
112 if (!(z >= FLT_MIN * 2.0f && z <= FLT_MIN * 4.0f))
115 /* This test fails on OpenBSD 4.9. */
120 if (!(z > 0 && z == z + z))
126 [gl_cv_func_hypotf_works=yes],
127 [gl_cv_func_hypotf_works=no],
129 netbsd* | openbsd*) gl_cv_func_hypotf_works="guessing no";;
130 *) gl_cv_func_hypotf_works="guessing yes";;