maint: update copyright
[gnulib.git] / m4 / cbrtf.m4
1 # cbrtf.m4 serial 3
2 dnl Copyright (C) 2012-2014 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_CBRTF],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_FUNC_CBRT])
11
12   dnl Persuade glibc <math.h> to declare cbrtf().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14
15   dnl Test whether cbrtf() exists. Assume that cbrtf(), if it exists, is
16   dnl defined in the same library as cbrt().
17   save_LIBS="$LIBS"
18   LIBS="$LIBS $CBRT_LIBM"
19   AC_CHECK_FUNCS([cbrtf])
20   LIBS="$save_LIBS"
21   if test $ac_cv_func_cbrtf = yes; then
22     CBRTF_LIBM="$CBRT_LIBM"
23     dnl Also check whether it's declared.
24     dnl IRIX 6.5 has cbrtf() in libm but doesn't declare it in <math.h>.
25     AC_CHECK_DECL([cbrtf], , [HAVE_DECL_CBRTF=0], [[#include <math.h>]])
26     save_LIBS="$LIBS"
27     LIBS="$LIBS $CBRTF_LIBM"
28     gl_FUNC_CBRTF_WORKS
29     LIBS="$save_LIBS"
30     case "$gl_cv_func_cbrtf_works" in
31       *yes) ;;
32       *) REPLACE_CBRTF=1 ;;
33     esac
34   else
35     HAVE_CBRTF=0
36     HAVE_DECL_CBRTF=0
37   fi
38   if test $HAVE_CBRTF = 0 || test $REPLACE_CBRTF = 1; then
39     dnl Find libraries needed to link lib/cbrtf.c.
40     AC_REQUIRE([gl_FUNC_FABSF])
41     AC_REQUIRE([gl_FUNC_FREXPF])
42     AC_REQUIRE([gl_FUNC_LDEXPF])
43     CBRTF_LIBM=
44     dnl Append $FABSF_LIBM to CBRTF_LIBM, avoiding gratuitous duplicates.
45     case " $CBRTF_LIBM " in
46       *" $FABSF_LIBM "*) ;;
47       *) CBRTF_LIBM="$CBRTF_LIBM $FABSF_LIBM" ;;
48     esac
49     dnl Append $FREXPF_LIBM to CBRTF_LIBM, avoiding gratuitous duplicates.
50     case " $CBRTF_LIBM " in
51       *" $FREXPF_LIBM "*) ;;
52       *) CBRTF_LIBM="$CBRTF_LIBM $FREXPF_LIBM" ;;
53     esac
54     dnl Append $LDEXPF_LIBM to CBRTF_LIBM, avoiding gratuitous duplicates.
55     case " $CBRTF_LIBM " in
56       *" $LDEXPF_LIBM "*) ;;
57       *) CBRTF_LIBM="$CBRTF_LIBM $LDEXPF_LIBM" ;;
58     esac
59   fi
60   AC_SUBST([CBRTF_LIBM])
61 ])
62
63 dnl Test whether cbrtf() works.
64 dnl It returns wrong values on IRIX 6.5.
65 AC_DEFUN([gl_FUNC_CBRTF_WORKS],
66 [
67   AC_REQUIRE([AC_PROG_CC])
68   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
69   AC_CACHE_CHECK([whether cbrtf works], [gl_cv_func_cbrtf_works],
70     [
71       AC_RUN_IFELSE(
72         [AC_LANG_SOURCE([[
73 #include <math.h>
74 volatile float x;
75 volatile float y;
76 int main ()
77 {
78   extern
79   #ifdef __cplusplus
80   "C"
81   #endif
82   float cbrtf (float);
83   /* This test fails on IRIX 6.5.  */
84   x = - 0.0f;
85   y = cbrtf (x);
86   if (!(y == 0.0f))
87     return 1;
88   return 0;
89 }
90 ]])],
91         [gl_cv_func_cbrtf_works=yes],
92         [gl_cv_func_cbrtf_works=no],
93         [case "$host_os" in
94            irix*) gl_cv_func_cbrtf_works="guessing no";;
95            *)     gl_cv_func_cbrtf_works="guessing yes";;
96          esac
97         ])
98     ])
99 ])