math: Ensure declarations of math functions.
[gnulib.git] / m4 / cbrtl.m4
1 # cbrtl.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_CBRTL],
8 [
9   m4_divert_text([DEFAULTS], [gl_cbrtl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_CBRT])
13
14   dnl Persuade glibc <math.h> to declare cbrtl().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16
17   dnl Test whether cbrtl() exists. Assume that cbrtl(), if it exists, is
18   dnl defined in the same library as cbrt().
19   save_LIBS="$LIBS"
20   LIBS="$LIBS $CBRT_LIBM"
21   AC_CHECK_FUNCS([cbrtl])
22   LIBS="$save_LIBS"
23   if test $ac_cv_func_cbrtl = yes; then
24     CBRTL_LIBM="$CBRT_LIBM"
25     dnl Also check whether it's declared.
26     dnl IRIX 6.5 has cbrtl() in libm but doesn't declare it in <math.h>.
27     AC_CHECK_DECL([cbrtl], , [HAVE_DECL_CBRTL=0], [[#include <math.h>]])
28     m4_ifdef([gl_FUNC_CBRTL_IEEE], [
29       if test $gl_cbrtl_required = ieee && test $REPLACE_CBRTL = 0; then
30         AC_CACHE_CHECK([whether cbrtl works according to ISO C 99 with IEC 60559],
31           [gl_cv_func_cbrtl_ieee],
32           [
33             save_LIBS="$LIBS"
34             LIBS="$LIBS $CBRTL_LIBM"
35             AC_RUN_IFELSE(
36               [AC_LANG_SOURCE([[
37 #ifndef __NO_MATH_INLINES
38 # define __NO_MATH_INLINES 1 /* for glibc */
39 #endif
40 #include <math.h>
41 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
42 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
43 static long double dummy (long double x) { return 0; }
44 int main (int argc, char *argv[])
45 {
46   extern
47   #ifdef __cplusplus
48   "C"
49   #endif
50   long double cbrtl (long double);
51   long double (*my_cbrtl) (long double) = argc ? cbrtl : dummy;
52   long double f;
53   /* Test cbrtl(-0.0).
54      This test fails on IRIX 6.5.  */
55   f = my_cbrtl (minus_zerol);
56   if (!(f == 0.0L) || (signbitl (minus_zerol) && !signbitl (f)))
57     return 1;
58   return 0;
59 }
60               ]])],
61               [gl_cv_func_cbrtl_ieee=yes],
62               [gl_cv_func_cbrtl_ieee=no],
63               [gl_cv_func_cbrtl_ieee="guessing no"])
64             LIBS="$save_LIBS"
65           ])
66         case "$gl_cv_func_cbrtl_ieee" in
67           *yes) ;;
68           *) REPLACE_CBRTL=1 ;;
69         esac
70       fi
71     ])
72   else
73     HAVE_CBRTL=0
74     HAVE_DECL_CBRTL=0
75   fi
76   if test $HAVE_CBRTL = 0 || test $REPLACE_CBRTL = 1; then
77     dnl Find libraries needed to link lib/cbrtl.c.
78     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
79       CBRTL_LIBM="$CBRT_LIBM"
80     else
81       AC_REQUIRE([gl_FUNC_FREXPL])
82       AC_REQUIRE([gl_FUNC_LDEXPL])
83       CBRTL_LIBM=
84       dnl Append $FREXPL_LIBM to CBRTL_LIBM, avoiding gratuitous duplicates.
85       case " $CBRTL_LIBM " in
86         *" $FREXPL_LIBM "*) ;;
87         *) CBRTL_LIBM="$CBRTL_LIBM $FREXPL_LIBM" ;;
88       esac
89       dnl Append $LDEXPL_LIBM to CBRTL_LIBM, avoiding gratuitous duplicates.
90       case " $CBRTL_LIBM " in
91         *" $LDEXPL_LIBM "*) ;;
92         *) CBRTL_LIBM="$CBRTL_LIBM $LDEXPL_LIBM" ;;
93       esac
94     fi
95   fi
96   AC_SUBST([CBRTL_LIBM])
97 ])