6212d7f1f2e3b06c196e5fb4492ece4a3680b424
[gnulib.git] / m4 / ceilf.m4
1 # ceilf.m4 serial 13
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_CEILF],
8 [
9   m4_divert_text([DEFAULTS], [gl_ceilf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Persuade glibc <math.h> to declare ceilf().
12   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13   dnl Test whether ceilf() is declared.
14   AC_CHECK_DECLS([ceilf], , , [[#include <math.h>]])
15   if test "$ac_cv_have_decl_ceilf" = yes; then
16     dnl Test whether ceilf() can be used without libm.
17     gl_FUNC_CEILF_LIBS
18     if test "$CEILF_LIBM" = "?"; then
19       dnl Sun C 5.0 on Solaris declares ceilf() and has it in the system-wide
20       dnl libm.so, but not in the libm.so that the compiler uses.
21       REPLACE_CEILF=1
22     fi
23     m4_ifdef([gl_FUNC_CEILF_IEEE], [
24       if test $gl_ceilf_required = ieee && test $REPLACE_CEILF = 0; then
25         AC_CACHE_CHECK([whether ceilf works according to ISO C 99 with IEC 60559],
26           [gl_cv_func_ceilf_ieee],
27           [
28             save_LIBS="$LIBS"
29             LIBS="$LIBS $CEILF_LIBM"
30             AC_RUN_IFELSE(
31               [AC_LANG_SOURCE([[
32 #ifndef __NO_MATH_INLINES
33 # define __NO_MATH_INLINES 1 /* for glibc */
34 #endif
35 #include <math.h>
36 ]gl_FLOAT_MINUS_ZERO_CODE[
37 ]gl_FLOAT_SIGNBIT_CODE[
38 static float dummy (float f) { return 0; }
39 int main (int argc, char *argv[])
40 {
41   float (*my_ceilf) (float) = argc ? ceilf : dummy;
42   int result = 0;
43   /* Test whether ceilf (-0.0f) is -0.0f.  */
44   if (signbitf (minus_zerof) && !signbitf (my_ceilf (minus_zerof)))
45     result |= 1;
46   /* Test whether ceilf (-0.3f) is -0.0f.  */
47   if (signbitf (-0.3f) && !signbitf (my_ceilf (-0.3f)))
48     result |= 2;
49   return result;
50 }
51               ]])],
52               [gl_cv_func_ceilf_ieee=yes],
53               [gl_cv_func_ceilf_ieee=no],
54               [gl_cv_func_ceilf_ieee="guessing no"])
55             LIBS="$save_LIBS"
56           ])
57         case "$gl_cv_func_ceilf_ieee" in
58           *yes) ;;
59           *) REPLACE_CEILF=1 ;;
60         esac
61       fi
62     ])
63   else
64     HAVE_DECL_CEILF=0
65   fi
66   if test $HAVE_DECL_CEILF = 0 || test $REPLACE_CEILF = 1; then
67     dnl No libraries are needed to link lib/ceilf.c.
68     CEILF_LIBM=
69   fi
70   AC_SUBST([CEILF_LIBM])
71 ])
72
73 # Determines the libraries needed to get the ceilf() function.
74 # Sets CEILF_LIBM.
75 AC_DEFUN([gl_FUNC_CEILF_LIBS],
76 [
77   gl_CACHE_VAL_SILENT([gl_cv_func_ceilf_libm], [
78     gl_cv_func_ceilf_libm=?
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            float (*funcptr) (float) = ceilf;
86            float x;]],
87          [[x = funcptr(x) + ceilf(x);]])],
88       [gl_cv_func_ceilf_libm=])
89     if test "$gl_cv_func_ceilf_libm" = "?"; then
90       save_LIBS="$LIBS"
91       LIBS="$LIBS -lm"
92       AC_LINK_IFELSE(
93         [AC_LANG_PROGRAM(
94            [[#ifndef __NO_MATH_INLINES
95              # define __NO_MATH_INLINES 1 /* for glibc */
96              #endif
97              #include <math.h>
98              float (*funcptr) (float) = ceilf;
99              float x;]],
100            [[x = funcptr(x) + ceilf(x);]])],
101         [gl_cv_func_ceilf_libm="-lm"])
102       LIBS="$save_LIBS"
103     fi
104   ])
105   CEILF_LIBM="$gl_cv_func_ceilf_libm"
106 ])