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