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"
24 m4_ifdef([gl_FUNC_HYPOTL_IEEE], [
25 if test $gl_hypotl_required = ieee && test $REPLACE_HYPOTL = 0; then
26 AC_CACHE_CHECK([whether hypotl works according to ISO C 99 with IEC 60559],
27 [gl_cv_func_hypotl_ieee],
30 LIBS="$LIBS $HYPOTL_LIBM"
33 #ifndef __NO_MATH_INLINES
34 # define __NO_MATH_INLINES 1 /* for glibc */
37 /* Compare two numbers with ==.
38 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
41 numeric_equal (long double x, long double y)
45 static long double dummy (long double x, long double y) { return 0; }
47 long double one = 1.0L;
48 int main (int argc, char *argv[])
50 long double (*my_hypotl) (long double, long double) = argc ? hypotl : dummy;
52 /* Test hypotl(NaN,Infinity).
53 This test fails on OSF/1 5.1 and native Windows. */
54 f = my_hypotl (zero / zero, one / zero);
55 if (!numeric_equal (f, f))
60 [gl_cv_func_hypotl_ieee=yes],
61 [gl_cv_func_hypotl_ieee=no],
62 [gl_cv_func_hypotl_ieee="guessing no"])
65 case "$gl_cv_func_hypotl_ieee" in
67 *) REPLACE_HYPOTL=1 ;;
74 if test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; then
75 dnl Find libraries needed to link lib/hypotl.c.
76 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
77 HYPOTL_LIBM="$HYPOT_LIBM"
79 AC_REQUIRE([gl_FUNC_FABSL])
80 AC_REQUIRE([gl_FUNC_FREXPL])
81 AC_REQUIRE([gl_FUNC_LDEXPL])
82 AC_REQUIRE([gl_FUNC_SQRTL])
84 dnl Append $FABSL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
85 case " $HYPOTL_LIBM " in
87 *) HYPOTL_LIBM="$HYPOTL_LIBM $FABSL_LIBM" ;;
89 dnl Append $FREXPL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
90 case " $HYPOTL_LIBM " in
91 *" $FREXPL_LIBM "*) ;;
92 *) HYPOTL_LIBM="$HYPOTL_LIBM $FREXPL_LIBM" ;;
94 dnl Append $LDEXPL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
95 case " $HYPOTL_LIBM " in
96 *" $LDEXPL_LIBM "*) ;;
97 *) HYPOTL_LIBM="$HYPOTL_LIBM $LDEXPL_LIBM" ;;
99 dnl Append $SQRTL_LIBM to HYPOTL_LIBM, avoiding gratuitous duplicates.
100 case " $HYPOTL_LIBM " in
101 *" $SQRTL_LIBM "*) ;;
102 *) HYPOTL_LIBM="$HYPOTL_LIBM $SQRTL_LIBM" ;;
106 AC_SUBST([HYPOTL_LIBM])