bump standards-version
[gnulib.git] / m4 / roundl.m4
1 # roundl.m4 serial 14
2 dnl Copyright (C) 2007, 2009-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_ROUNDL],
8 [
9   m4_divert_text([DEFAULTS], [gl_roundl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12
13   dnl Persuade glibc <math.h> to declare roundl().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16   gl_CHECK_MATH_LIB([ROUNDL_LIBM], [x = roundl (x);],
17     [extern
18      #ifdef __cplusplus
19      "C"
20      #endif
21      long double roundl (long double);
22     ])
23   if test "$ROUNDL_LIBM" != missing; then
24     HAVE_ROUNDL=1
25     dnl Also check whether it's declared.
26     dnl IRIX 6.5 has roundl() in libm but doesn't declare it in <math.h>.
27     AC_CHECK_DECLS([roundl], , [HAVE_DECL_ROUNDL=0], [[#include <math.h>]])
28
29     m4_ifdef([gl_FUNC_ROUNDL_IEEE], [
30       if test $gl_roundl_required = ieee && test $REPLACE_ROUNDL = 0; then
31         AC_CACHE_CHECK([whether roundl works according to ISO C 99 with IEC 60559],
32           [gl_cv_func_roundl_ieee],
33           [
34             save_LIBS="$LIBS"
35             LIBS="$LIBS $ROUNDL_LIBM"
36             AC_RUN_IFELSE(
37               [AC_LANG_SOURCE([[
38 #ifndef __NO_MATH_INLINES
39 # define __NO_MATH_INLINES 1 /* for glibc */
40 #endif
41 #include <math.h>
42 extern
43 #ifdef __cplusplus
44 "C"
45 #endif
46 long double roundl (long double);
47 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
48 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
49 static long double dummy (long double f) { return 0; }
50 int main (int argc, char *argv[])
51 {
52   long double (*my_roundl) (long double) = argc ? roundl : dummy;
53   int result = 0;
54   /* Test whether roundl (-0.0L) is -0.0L.  */
55   if (signbitl (minus_zerol) && !signbitl (my_roundl (minus_zerol)))
56     result |= 1;
57   /* Test whether roundl (-0.3L) is -0.0L.  */
58   if (signbitl (-0.3L) && !signbitl (my_roundl (-0.3L)))
59     result |= 2;
60   return result;
61 }
62               ]])],
63               [gl_cv_func_roundl_ieee=yes],
64               [gl_cv_func_roundl_ieee=no],
65               [gl_cv_func_roundl_ieee="guessing no"])
66             LIBS="$save_LIBS"
67           ])
68         case "$gl_cv_func_roundl_ieee" in
69           *yes) ;;
70           *) REPLACE_ROUNDL=1 ;;
71         esac
72       fi
73     ])
74   else
75     HAVE_ROUNDL=0
76     HAVE_DECL_ROUNDL=0
77   fi
78   if test $HAVE_ROUNDL = 0 || test $REPLACE_ROUNDL = 1; then
79     dnl Find libraries needed to link lib/roundl.c.
80     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
81       AC_REQUIRE([gl_FUNC_ROUND])
82       ROUNDL_LIBM="$ROUND_LIBM"
83     else
84       AC_CHECK_DECLS([ceill, floorl], , , [[#include <math.h>]])
85       if test "$ac_cv_have_decl_floorl" = yes \
86          && test "$ac_cv_have_decl_ceill" = yes; then
87         gl_FUNC_FLOORL_LIBS
88         gl_FUNC_CEILL_LIBS
89         if test "$FLOORL_LIBM" != '?' && test "$CEILL_LIBM" != '?'; then
90           AC_DEFINE([HAVE_FLOORL_AND_CEILL], [1],
91             [Define if the both the floorl() and ceill() functions exist.])
92           ROUNDL_LIBM=
93           dnl Append $FLOORL_LIBM to ROUNDL_LIBM, avoiding gratuitous duplicates.
94           case " $ROUNDL_LIBM " in
95             *" $FLOORL_LIBM "*) ;;
96             *) ROUNDL_LIBM="$ROUNDL_LIBM $FLOORL_LIBM" ;;
97           esac
98           dnl Append $CEILL_LIBM to ROUNDL_LIBM, avoiding gratuitous duplicates.
99           case " $ROUNDL_LIBM " in
100             *" $CEILL_LIBM "*) ;;
101             *) ROUNDL_LIBM="$ROUNDL_LIBM $CEILL_LIBM" ;;
102           esac
103         else
104           ROUNDL_LIBM=
105         fi
106       else
107         ROUNDL_LIBM=
108       fi
109     fi
110   fi
111   AC_SUBST([ROUNDL_LIBM])
112 ])