frexp-nolibm, frexpl-nolibm tests: Fix bug introduced on 2012-03-03.
[gnulib.git] / m4 / hypot.m4
1 # hypot.m4 serial 3
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.
6
7 AC_DEFUN([gl_FUNC_HYPOT],
8 [
9   m4_divert_text([DEFAULTS], [gl_hypot_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11
12   dnl Persuade glibc <math.h> to declare hypot().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14
15   dnl Determine HYPOT_LIBM.
16   gl_COMMON_DOUBLE_MATHFUNC([hypot])
17
18   m4_ifdef([gl_FUNC_HYPOT_IEEE], [
19     if test $gl_hypot_required = ieee && test $REPLACE_HYPOT = 0; then
20       AC_CACHE_CHECK([whether hypot works according to ISO C 99 with IEC 60559],
21         [gl_cv_func_hypot_ieee],
22         [
23           save_LIBS="$LIBS"
24           LIBS="$LIBS $HYPOT_LIBM"
25           AC_RUN_IFELSE(
26             [AC_LANG_SOURCE([[
27 #ifndef __NO_MATH_INLINES
28 # define __NO_MATH_INLINES 1 /* for glibc */
29 #endif
30 #include <math.h>
31 /* Compare two numbers with ==.
32    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
33    'x == x' test.  */
34 static int
35 numeric_equal (double x, double y)
36 {
37   return x == y;
38 }
39 static double dummy (double x, double y) { return 0; }
40 double zero;
41 double one = 1.0;
42 int main (int argc, char *argv[])
43 {
44   double (*my_hypot) (double, double) = argc ? hypot : dummy;
45   double f;
46   /* Test hypot(NaN,Infinity).
47      This test fails on OSF/1 5.1 and native Windows.  */
48   f = my_hypot (zero / zero, one / zero);
49   if (!numeric_equal (f, f))
50     return 1;
51   return 0;
52 }
53             ]])],
54             [gl_cv_func_hypot_ieee=yes],
55             [gl_cv_func_hypot_ieee=no],
56             [gl_cv_func_hypot_ieee="guessing no"])
57           LIBS="$save_LIBS"
58         ])
59       case "$gl_cv_func_hypot_ieee" in
60         *yes) ;;
61         *) REPLACE_HYPOT=1 ;;
62       esac
63     fi
64   ])
65   if test $REPLACE_HYPOT = 1; then
66     dnl Find libraries needed to link lib/hypot.c.
67     AC_REQUIRE([gl_FUNC_FABS])
68     AC_REQUIRE([gl_FUNC_FREXP])
69     AC_REQUIRE([gl_FUNC_LDEXP])
70     AC_REQUIRE([gl_FUNC_SQRT])
71     HYPOT_LIBM=
72     dnl Append $FABS_LIBM to HYPOT_LIBM, avoiding gratuitous duplicates.
73     case " $HYPOT_LIBM " in
74       *" $FABS_LIBM "*) ;;
75       *) HYPOT_LIBM="$HYPOT_LIBM $FABS_LIBM" ;;
76     esac
77     dnl Append $FREXP_LIBM to HYPOT_LIBM, avoiding gratuitous duplicates.
78     case " $HYPOT_LIBM " in
79       *" $FREXP_LIBM "*) ;;
80       *) HYPOT_LIBM="$HYPOT_LIBM $FREXP_LIBM" ;;
81     esac
82     dnl Append $LDEXP_LIBM to HYPOT_LIBM, avoiding gratuitous duplicates.
83     case " $HYPOT_LIBM " in
84       *" $LDEXP_LIBM "*) ;;
85       *) HYPOT_LIBM="$HYPOT_LIBM $LDEXP_LIBM" ;;
86     esac
87     dnl Append $SQRT_LIBM to HYPOT_LIBM, avoiding gratuitous duplicates.
88     case " $HYPOT_LIBM " in
89       *" $SQRT_LIBM "*) ;;
90       *) HYPOT_LIBM="$HYPOT_LIBM $SQRT_LIBM" ;;
91     esac
92   fi
93 ])