2 dnl Copyright (C) 2012-2020 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"
26 LIBS="$LIBS $HYPOTF_LIBM"
29 case "$gl_cv_func_hypotf_works" in
31 *) REPLACE_HYPOTF=1 ;;
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],
41 LIBS="$LIBS $HYPOTF_LIBM"
44 #ifndef __NO_MATH_INLINES
45 # define __NO_MATH_INLINES 1 /* for glibc */
48 /* Compare two numbers with ==.
49 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
52 numeric_equal (float x, float y)
56 static float dummy (float x, float y) { return 0; }
59 int main (int argc, char *argv[])
61 float (* volatile my_hypotf) (float, float) = argc ? hypotf : dummy;
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))
71 [gl_cv_func_hypotf_ieee=yes],
72 [gl_cv_func_hypotf_ieee=no],
74 # Guess yes on glibc systems.
75 *-gnu* | gnu*) gl_cv_func_hypotf_ieee="guessing yes" ;;
76 # Guess yes on musl systems.
77 *-musl*) gl_cv_func_hypotf_ieee="guessing yes" ;;
78 # Guess yes on native Windows.
79 mingw*) gl_cv_func_hypotf_ieee="guessing yes" ;;
80 # If we don't know, obey --enable-cross-guesses.
81 *) gl_cv_func_hypotf_ieee="$gl_cross_guess_normal" ;;
86 case "$gl_cv_func_hypotf_ieee" in
88 *) REPLACE_HYPOTF=1 ;;
94 dnl If the function is declared but does not appear to exist, it may be
95 dnl defined as an inline function. In order to avoid a conflict, we have
96 dnl to define rpl_hypotf, not hypotf.
97 AC_CHECK_DECLS([hypotf], [REPLACE_HYPOTF=1], , [[#include <math.h>]])
99 if test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1; then
100 dnl Find libraries needed to link lib/hypotf.c.
101 HYPOTF_LIBM="$HYPOT_LIBM"
103 AC_SUBST([HYPOTF_LIBM])
106 dnl Test whether hypotf() works.
107 dnl It returns wrong values on NetBSD 5.1/x86_64 and OpenBSD 4.9/x86.
108 AC_DEFUN([gl_FUNC_HYPOTF_WORKS],
110 AC_REQUIRE([AC_PROG_CC])
111 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
112 AC_CACHE_CHECK([whether hypotf works], [gl_cv_func_hypotf_works],
124 /* This test fails on NetBSD 5.1. */
129 if (!(z >= FLT_MIN * 2.0f && z <= FLT_MIN * 4.0f))
132 /* This test fails on OpenBSD 4.9. */
137 if (!(z > 0 && z == z + z))
143 [gl_cv_func_hypotf_works=yes],
144 [gl_cv_func_hypotf_works=no],
146 netbsd* | openbsd*) gl_cv_func_hypotf_works="guessing no" ;;
147 # Guess yes on native Windows.
148 mingw*) gl_cv_func_hypotf_works="guessing yes" ;;
149 *) gl_cv_func_hypotf_works="guessing yes" ;;