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_HYPOTL],
10 m4_divert_text([DEFAULTS], [gl_hypotl_required=plain])
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 AC_REQUIRE([gl_FUNC_HYPOT])
14 dnl Persuade glibc <math.h> to declare hypotl().
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17 dnl Test whether hypotl() exists. Assume that hypotl(), if it exists, is
18 dnl defined in the same library as hypot().
20 LIBS="$LIBS $HYPOT_LIBM"
21 AC_CHECK_FUNCS([hypotl])
23 if test $ac_cv_func_hypotl = yes; then
24 HYPOTL_LIBM="$HYPOT_LIBM"
27 LIBS="$LIBS $HYPOTL_LIBM"
30 case "$gl_cv_func_hypotl_works" in
32 *) REPLACE_HYPOTL=1 ;;
35 m4_ifdef([gl_FUNC_HYPOTL_IEEE], [
36 if test $gl_hypotl_required = ieee && test $REPLACE_HYPOTL = 0; then
37 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
38 AC_CACHE_CHECK([whether hypotl works according to ISO C 99 with IEC 60559],
39 [gl_cv_func_hypotl_ieee],
42 LIBS="$LIBS $HYPOTL_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 (long double x, long double y)
57 static long double dummy (long double x, long double y) { return 0; }
59 long double one = 1.0L;
60 int main (int argc, char *argv[])
62 long double (* volatile my_hypotl) (long double, long double) = argc ? hypotl : dummy;
64 /* Test hypotl(NaN,Infinity).
65 This test fails on OSF/1 5.1 and native Windows. */
66 f = my_hypotl (zero / zero, one / zero);
67 if (!numeric_equal (f, f))
72 [gl_cv_func_hypotl_ieee=yes],
73 [gl_cv_func_hypotl_ieee=no],
75 # Guess yes on glibc systems.
76 *-gnu* | gnu*) gl_cv_func_hypotl_ieee="guessing yes" ;;
77 # Guess yes on musl systems.
78 *-musl* | midipix*) gl_cv_func_hypotl_ieee="guessing yes" ;;
79 # Guess yes on native Windows.
80 mingw* | windows*) gl_cv_func_hypotl_ieee="guessing yes" ;;
81 # If we don't know, obey --enable-cross-guesses.
82 *) gl_cv_func_hypotl_ieee="$gl_cross_guess_normal" ;;
87 case "$gl_cv_func_hypotl_ieee" in
89 *) REPLACE_HYPOTL=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_hypotl, not hypotl.
98 AC_CHECK_DECLS([hypotl], [REPLACE_HYPOTL=1], , [[#include <math.h>]])
100 if test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; then
101 dnl Find libraries needed to link lib/hypotl.c.
102 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
103 HYPOTL_LIBM="$HYPOT_LIBM"
105 AC_REQUIRE([gl_FUNC_FABSL])
106 AC_REQUIRE([gl_FUNC_FREXPL])
107 AC_REQUIRE([gl_FUNC_LDEXPL])
108 AC_REQUIRE([gl_FUNC_SQRTL])
110 dnl Append $FABSL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
111 case " $HYPOTL_LIBM " in
112 *" $FABSL_LIBM "*) ;;
113 *) HYPOTL_LIBM="$HYPOTL_LIBM $FABSL_LIBM" ;;
115 dnl Append $FREXPL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
116 case " $HYPOTL_LIBM " in
117 *" $FREXPL_LIBM "*) ;;
118 *) HYPOTL_LIBM="$HYPOTL_LIBM $FREXPL_LIBM" ;;
120 dnl Append $LDEXPL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
121 case " $HYPOTL_LIBM " in
122 *" $LDEXPL_LIBM "*) ;;
123 *) HYPOTL_LIBM="$HYPOTL_LIBM $LDEXPL_LIBM" ;;
125 dnl Append $SQRTL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
126 case " $HYPOTL_LIBM " in
127 *" $SQRTL_LIBM "*) ;;
128 *) HYPOTL_LIBM="$HYPOTL_LIBM $SQRTL_LIBM" ;;
132 AC_SUBST([HYPOTL_LIBM])
135 dnl Test whether hypotl() works.
136 dnl On OpenBSD 5.1/SPARC,
137 dnl hypotl (2.5541394760659556563446062497337725156L, 7.7893454113437840832487794525518765265L)
138 dnl has rounding errors that eat up the last 8 to 9 decimal digits.
139 dnl On NetBSD 9.3, the result is accurate to only 16 digits.
140 AC_DEFUN([gl_FUNC_HYPOTL_WORKS],
142 AC_REQUIRE([AC_PROG_CC])
143 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
144 AC_CACHE_CHECK([whether hypotl works], [gl_cv_func_hypotl_works],
151 my_ldexpl (long double x, int d)
159 volatile long double x;
160 volatile long double y;
161 volatile long double z;
166 x = 2.5541394760659556563446062497337725156L;
167 y = 7.7893454113437840832487794525518765265L;
169 err = z * z - (x * x + y * y);
170 err = my_ldexpl (err, LDBL_MANT_DIG);
178 [gl_cv_func_hypotl_works=yes],
179 [gl_cv_func_hypotl_works=no],
181 openbsd*) gl_cv_func_hypotl_works="guessing no" ;;
182 # Guess yes on native Windows.
183 mingw* | windows*) gl_cv_func_hypotl_works="guessing yes" ;;
184 *) gl_cv_func_hypotl_works="guessing yes" ;;