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