3 dnl Copyright (C) 2012-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_HYPOTF],
10 m4_divert_text([DEFAULTS], [gl_hypotf_required=plain])
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 AC_REQUIRE([gl_FUNC_HYPOT])
14 dnl Persuade glibc <math.h> to declare hypotf().
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17 dnl Test whether hypotf() exists. Assume that hypotf(), if it exists, is
18 dnl defined in the same library as hypot().
20 LIBS="$LIBS $HYPOT_LIBM"
21 AC_CHECK_FUNCS([hypotf])
23 if test $ac_cv_func_hypotf = yes; then
24 HYPOTF_LIBM="$HYPOT_LIBM"
27 LIBS="$LIBS $HYPOTF_LIBM"
30 case "$gl_cv_func_hypotf_works" in
32 *) REPLACE_HYPOTF=1 ;;
35 m4_ifdef([gl_FUNC_HYPOTF_IEEE], [
36 if test $gl_hypotf_required = ieee && test $REPLACE_HYPOTF = 0; then
37 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
38 AC_CACHE_CHECK([whether hypotf works according to ISO C 99 with IEC 60559],
39 [gl_cv_func_hypotf_ieee],
42 LIBS="$LIBS $HYPOTF_LIBM"
45 #ifndef __NO_MATH_INLINES
46 # define __NO_MATH_INLINES 1 /* for glibc */
49 /* Compare two numbers with ==.
50 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
53 numeric_equal (float x, float y)
57 static float dummy (float x, float y) { return 0; }
60 int main (int argc, char *argv[])
62 float (* volatile my_hypotf) (float, float) = argc ? hypotf : dummy;
64 /* Test hypotf(NaN,Infinity).
65 This test fails on OSF/1 5.1 and native Windows. */
66 f = my_hypotf (zero / zero, one / zero);
67 if (!numeric_equal (f, f))
72 [gl_cv_func_hypotf_ieee=yes],
73 [gl_cv_func_hypotf_ieee=no],
75 # Guess yes on glibc systems.
76 *-gnu* | gnu*) gl_cv_func_hypotf_ieee="guessing yes" ;;
77 # Guess yes on musl systems.
78 *-musl* | midipix*) gl_cv_func_hypotf_ieee="guessing yes" ;;
79 # Guess yes on native Windows.
80 mingw* | windows*) gl_cv_func_hypotf_ieee="guessing yes" ;;
81 # If we don't know, obey --enable-cross-guesses.
82 *) gl_cv_func_hypotf_ieee="$gl_cross_guess_normal" ;;
87 case "$gl_cv_func_hypotf_ieee" in
89 *) REPLACE_HYPOTF=1 ;;
95 dnl If the function is declared but does not appear to exist, it may be
96 dnl defined as an inline function. In order to avoid a conflict, we have
97 dnl to define rpl_hypotf, not hypotf.
98 AC_CHECK_DECLS([hypotf], [REPLACE_HYPOTF=1], , [[#include <math.h>]])
100 if test $HAVE_HYPOTF = 0 || test $REPLACE_HYPOTF = 1; then
101 dnl Find libraries needed to link lib/hypotf.c.
102 HYPOTF_LIBM="$HYPOT_LIBM"
104 AC_SUBST([HYPOTF_LIBM])
107 dnl Test whether hypotf() works.
108 dnl It returns wrong values on NetBSD 5.1/x86_64 and OpenBSD 4.9/x86.
109 AC_DEFUN([gl_FUNC_HYPOTF_WORKS],
111 AC_REQUIRE([AC_PROG_CC])
112 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
113 AC_CACHE_CHECK([whether hypotf works], [gl_cv_func_hypotf_works],
125 /* This test fails on NetBSD 5.1. */
130 if (!(z >= FLT_MIN * 2.0f && z <= FLT_MIN * 4.0f))
133 /* This test fails on OpenBSD 4.9. */
138 if (!(z > 0 && z == z + z))
144 [gl_cv_func_hypotf_works=yes],
145 [gl_cv_func_hypotf_works=no],
147 netbsd* | openbsd*) gl_cv_func_hypotf_works="guessing no" ;;
148 # Guess yes on native Windows.
149 mingw* | windows*) gl_cv_func_hypotf_works="guessing yes" ;;
150 *) gl_cv_func_hypotf_works="guessing yes" ;;