ceil-ieee: Work around bug on AIX 7.1.
[gnulib.git] / m4 / ceil.m4
1 # ceil.m4 serial 7
2 dnl Copyright (C) 2007, 2009-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_CEIL],
8 [
9   m4_divert_text([DEFAULTS], [gl_ceil_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Test whether ceil() can be used without libm.
12   gl_FUNC_CEIL_LIBS
13   if test "$CEIL_LIBM" = "?"; then
14     CEIL_LIBM=
15   fi
16   m4_ifdef([gl_FUNC_CEIL_IEEE], [
17     if test $gl_ceil_required = ieee && test $REPLACE_CEIL = 0; then
18       AC_CACHE_CHECK([whether ceil works according to ISO C 99 with IEC 60559],
19         [gl_cv_func_ceil_ieee],
20         [
21           save_LIBS="$LIBS"
22           LIBS="$LIBS $CEIL_LIBM"
23           AC_RUN_IFELSE(
24             [AC_LANG_SOURCE([[
25 #ifndef __NO_MATH_INLINES
26 # define __NO_MATH_INLINES 1 /* for glibc */
27 #endif
28 #include <math.h>
29 ]gl_DOUBLE_MINUS_ZERO_CODE[
30 ]gl_DOUBLE_SIGNBIT_CODE[
31 int main()
32 {
33   int result = 0;
34   /* Test whether ceil (-0.0) is -0.0.  */
35   if (signbitd (minus_zerod) && !signbitd (ceil (minus_zerod)))
36     result |= 1;
37   /* Test whether ceil (-0.3) is -0.0.  */
38   if (signbitd (-0.3) && !signbitd (ceil (-0.3)))
39     result |= 2;
40   return result;
41 }
42             ]])],
43             [gl_cv_func_ceil_ieee=yes],
44             [gl_cv_func_ceil_ieee=no],
45             [gl_cv_func_ceil_ieee="guessing no"])
46           LIBS="$save_LIBS"
47         ])
48       case "$gl_cv_func_ceil_ieee" in
49         *yes) ;;
50         *) REPLACE_CEIL=1 ;;
51       esac
52     fi
53   ])
54   if test $REPLACE_CEIL = 1; then
55     dnl No libraries are needed to link lib/ceil.c.
56     CEIL_LIBM=
57   fi
58   AC_SUBST([CEIL_LIBM])
59 ])
60
61 # Determines the libraries needed to get the ceil() function.
62 # Sets CEIL_LIBM.
63 AC_DEFUN([gl_FUNC_CEIL_LIBS],
64 [
65   gl_CACHE_VAL_SILENT([gl_cv_func_ceil_libm], [
66     gl_cv_func_ceil_libm=?
67     AC_LINK_IFELSE(
68       [AC_LANG_PROGRAM(
69          [[#ifndef __NO_MATH_INLINES
70            # define __NO_MATH_INLINES 1 /* for glibc */
71            #endif
72            #include <math.h>
73            double x;]],
74          [[x = ceil(x);]])],
75       [gl_cv_func_ceil_libm=])
76     if test "$gl_cv_func_ceil_libm" = "?"; then
77       save_LIBS="$LIBS"
78       LIBS="$LIBS -lm"
79       AC_LINK_IFELSE(
80         [AC_LANG_PROGRAM(
81            [[#ifndef __NO_MATH_INLINES
82              # define __NO_MATH_INLINES 1 /* for glibc */
83              #endif
84              #include <math.h>
85              double x;]],
86            [[x = ceil(x);]])],
87         [gl_cv_func_ceil_libm="-lm"])
88       LIBS="$save_LIBS"
89     fi
90   ])
91   CEIL_LIBM="$gl_cv_func_ceil_libm"
92 ])