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_HYPOTL],
9 m4_divert_text([DEFAULTS], [gl_hypotl_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_FUNC_HYPOT])
13 dnl Persuade glibc <math.h> to declare hypotl().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 dnl Test whether hypotl() exists. Assume that hypotl(), if it exists, is
17 dnl defined in the same library as hypot().
19 LIBS="$LIBS $HYPOT_LIBM"
20 AC_CHECK_FUNCS([hypotl])
22 if test $ac_cv_func_hypotl = yes; then
23 HYPOTL_LIBM="$HYPOT_LIBM"
26 LIBS="$LIBS $HYPOTL_LIBM"
29 case "$gl_cv_func_hypotl_works" in
31 *) REPLACE_HYPOTL=1 ;;
34 m4_ifdef([gl_FUNC_HYPOTL_IEEE], [
35 if test $gl_hypotl_required = ieee && test $REPLACE_HYPOTL = 0; then
36 AC_CACHE_CHECK([whether hypotl works according to ISO C 99 with IEC 60559],
37 [gl_cv_func_hypotl_ieee],
40 LIBS="$LIBS $HYPOTL_LIBM"
43 #ifndef __NO_MATH_INLINES
44 # define __NO_MATH_INLINES 1 /* for glibc */
47 /* Compare two numbers with ==.
48 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
51 numeric_equal (long double x, long double y)
55 static long double dummy (long double x, long double y) { return 0; }
57 long double one = 1.0L;
58 int main (int argc, char *argv[])
60 long double (*my_hypotl) (long double, long double) = argc ? hypotl : dummy;
62 /* Test hypotl(NaN,Infinity).
63 This test fails on OSF/1 5.1 and native Windows. */
64 f = my_hypotl (zero / zero, one / zero);
65 if (!numeric_equal (f, f))
70 [gl_cv_func_hypotl_ieee=yes],
71 [gl_cv_func_hypotl_ieee=no],
72 [gl_cv_func_hypotl_ieee="guessing no"])
75 case "$gl_cv_func_hypotl_ieee" in
77 *) REPLACE_HYPOTL=1 ;;
84 if test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; then
85 dnl Find libraries needed to link lib/hypotl.c.
86 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
87 HYPOTL_LIBM="$HYPOT_LIBM"
89 AC_REQUIRE([gl_FUNC_FABSL])
90 AC_REQUIRE([gl_FUNC_FREXPL])
91 AC_REQUIRE([gl_FUNC_LDEXPL])
92 AC_REQUIRE([gl_FUNC_SQRTL])
94 dnl Append $FABSL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
95 case " $HYPOTL_LIBM " in
97 *) HYPOTL_LIBM="$HYPOTL_LIBM $FABSL_LIBM" ;;
99 dnl Append $FREXPL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
100 case " $HYPOTL_LIBM " in
101 *" $FREXPL_LIBM "*) ;;
102 *) HYPOTL_LIBM="$HYPOTL_LIBM $FREXPL_LIBM" ;;
104 dnl Append $LDEXPL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
105 case " $HYPOTL_LIBM " in
106 *" $LDEXPL_LIBM "*) ;;
107 *) HYPOTL_LIBM="$HYPOTL_LIBM $LDEXPL_LIBM" ;;
109 dnl Append $SQRTL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
110 case " $HYPOTL_LIBM " in
111 *" $SQRTL_LIBM "*) ;;
112 *) HYPOTL_LIBM="$HYPOTL_LIBM $SQRTL_LIBM" ;;
116 AC_SUBST([HYPOTL_LIBM])
119 dnl Test whether hypotl() works.
120 dnl On OpenBSD 5.1/SPARC,
121 dnl hypotl (2.5541394760659556563446062497337725156L, 7.7893454113437840832487794525518765265L)
122 dnl has rounding errors that eat up the last 8 to 9 decimal digits.
123 AC_DEFUN([gl_FUNC_HYPOTL_WORKS],
125 AC_REQUIRE([AC_PROG_CC])
126 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
127 AC_CACHE_CHECK([whether hypotl works], [gl_cv_func_hypotl_works],
134 my_ldexpl (long double x, int d)
142 volatile long double x;
143 volatile long double y;
144 volatile long double z;
149 x = 2.5541394760659556563446062497337725156L;
150 y = 7.7893454113437840832487794525518765265L;
152 err = z * z - (x * x + y * y);
153 err = my_ldexpl (err, LDBL_MANT_DIG);
161 [gl_cv_func_hypotl_works=yes],
162 [gl_cv_func_hypotl_works=no],
164 openbsd*) gl_cv_func_hypotl_works="guessing no";;
165 *) gl_cv_func_hypotl_works="guessing yes";;