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