Merge commit 'stable/20110609'
[gnulib.git] / m4 / truncl.m4
1 # truncl.m4 serial 6
2 dnl Copyright (C) 2007-2008, 2010-2011 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_TRUNCL],
8 [
9   m4_divert_text([DEFAULTS], [gl_truncl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   dnl Persuade glibc <math.h> to declare truncl().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14   dnl Test whether truncl() is declared.
15   AC_CHECK_DECLS([truncl], , , [#include <math.h>])
16   if test "$ac_cv_have_decl_truncl" = yes; then
17     dnl Test whether truncl() can be used without libm.
18     TRUNCL_LIBM=?
19     AC_LINK_IFELSE(
20       [AC_LANG_PROGRAM(
21          [[#ifndef __NO_MATH_INLINES
22            # define __NO_MATH_INLINES 1 /* for glibc */
23            #endif
24            #include <math.h>
25            long double x;]],
26          [[x = truncl(x);]])],
27       [TRUNCL_LIBM=])
28     if test "$TRUNCL_LIBM" = "?"; then
29       save_LIBS="$LIBS"
30       LIBS="$LIBS -lm"
31       AC_LINK_IFELSE(
32         [AC_LANG_PROGRAM(
33            [[#ifndef __NO_MATH_INLINES
34              # define __NO_MATH_INLINES 1 /* for glibc */
35              #endif
36              #include <math.h>
37              long double x;]],
38            [[x = truncl(x);]])],
39         [TRUNCL_LIBM="-lm"])
40       LIBS="$save_LIBS"
41     fi
42     if test "$TRUNCL_LIBM" = "?"; then
43       TRUNCL_LIBM=
44     fi
45     dnl Test whether truncl() works. It crashes on OSF/1 4.0d.
46     save_LIBS="$LIBS"
47     LIBS="$LIBS $TRUNCL_LIBM"
48     AC_CACHE_CHECK([whether truncl works], [gl_cv_func_truncl_works],
49       [
50         AC_RUN_IFELSE(
51           [AC_LANG_SOURCE([[
52 #include <math.h>
53 long double x;
54 int main()
55 {
56   x = truncl (0.0L);
57   return 0;
58 }]])],
59           [gl_cv_func_truncl_works=yes],
60           [gl_cv_func_truncl_works=no],
61           [case "$host_os" in
62              osf4*) gl_cv_func_truncl_works="guessing no";;
63              *)     gl_cv_func_truncl_works="guessing yes";;
64            esac
65           ])
66       ])
67     LIBS="$save_LIBS"
68     case "$gl_cv_func_truncl_works" in
69       *yes) ;;
70       *) REPLACE_TRUNCL=1 ;;
71     esac
72     m4_ifdef([gl_FUNC_TRUNCL_IEEE], [
73       if test $gl_truncl_required = ieee && test $REPLACE_TRUNCL = 0; then
74         AC_CACHE_CHECK([whether truncl works according to ISO C 99 with IEC 60559],
75           [gl_cv_func_truncl_ieee],
76           [
77             save_LIBS="$LIBS"
78             LIBS="$LIBS $TRUNCL_LIBM"
79             AC_RUN_IFELSE(
80               [AC_LANG_SOURCE([[
81 #ifndef __NO_MATH_INLINES
82 # define __NO_MATH_INLINES 1 /* for glibc */
83 #endif
84 #include <math.h>
85 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
86 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
87 int main()
88 {
89   /* Test whether truncl (-0.3L) is -0.0L.  */
90   if (signbitl (minus_zerol) && !signbitl (truncl (-0.3L)))
91     return 1;
92   return 0;
93 }
94               ]])],
95               [gl_cv_func_truncl_ieee=yes],
96               [gl_cv_func_truncl_ieee=no],
97               [gl_cv_func_truncl_ieee="guessing no"])
98             LIBS="$save_LIBS"
99           ])
100         case "$gl_cv_func_truncl_ieee" in
101           *yes) ;;
102           *) REPLACE_TRUNCL=1 ;;
103         esac
104       fi
105     ])
106   else
107     HAVE_DECL_TRUNCL=0
108   fi
109   if test $HAVE_DECL_TRUNCL = 0 || test $REPLACE_TRUNCL = 1; then
110     AC_LIBOBJ([truncl])
111     TRUNCL_LIBM=
112   fi
113   AC_SUBST([TRUNCL_LIBM])
114 ])