6e792a1ffe86a38f3ec93745da4a13bc20e38f8b
[gnulib.git] / m4 / floorf.m4
1 # floorf.m4 serial 12
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_FLOORF],
8 [
9   m4_divert_text([DEFAULTS], [gl_floorf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Persuade glibc <math.h> to declare floorf().
12   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13   dnl Test whether floorf() is declared.
14   AC_CHECK_DECLS([floorf], , , [[#include <math.h>]])
15   if test "$ac_cv_have_decl_floorf" = yes; then
16     dnl Test whether floorf() can be used without libm.
17     gl_FUNC_FLOORF_LIBS
18     if test "$FLOORF_LIBM" = "?"; then
19       dnl Sun C 5.0 on Solaris declares floorf() and has it in the system-wide
20       dnl libm.so, but not in the libm.so that the compiler uses.
21       REPLACE_FLOORF=1
22     fi
23     m4_ifdef([gl_FUNC_FLOORF_IEEE], [
24       if test $gl_floorf_required = ieee && test $REPLACE_FLOORF = 0; then
25         AC_CACHE_CHECK([whether floorf works according to ISO C 99 with IEC 60559],
26           [gl_cv_func_floorf_ieee],
27           [
28             save_LIBS="$LIBS"
29             LIBS="$LIBS $FLOORF_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_floorf) (float) = argc ? floorf : dummy;
42   /* Test whether floorf (-0.0f) is -0.0f.  */
43   if (signbitf (minus_zerof) && !signbitf (my_floorf (minus_zerof)))
44     return 1;
45   return 0;
46 }
47               ]])],
48               [gl_cv_func_floorf_ieee=yes],
49               [gl_cv_func_floorf_ieee=no],
50               [gl_cv_func_floorf_ieee="guessing no"])
51             LIBS="$save_LIBS"
52           ])
53         case "$gl_cv_func_floorf_ieee" in
54           *yes) ;;
55           *) REPLACE_FLOORF=1 ;;
56         esac
57       fi
58     ])
59   else
60     HAVE_DECL_FLOORF=0
61   fi
62   if test $HAVE_DECL_FLOORF = 0 || test $REPLACE_FLOORF = 1; then
63     dnl No libraries are needed to link lib/floorf.c.
64     FLOORF_LIBM=
65   fi
66   AC_SUBST([FLOORF_LIBM])
67 ])
68
69 # Determines the libraries needed to get the floorf() function.
70 # Sets FLOORF_LIBM.
71 AC_DEFUN([gl_FUNC_FLOORF_LIBS],
72 [
73   gl_CACHE_VAL_SILENT([gl_cv_func_floorf_libm], [
74     gl_cv_func_floorf_libm=?
75     AC_LINK_IFELSE(
76       [AC_LANG_PROGRAM(
77          [[#ifndef __NO_MATH_INLINES
78            # define __NO_MATH_INLINES 1 /* for glibc */
79            #endif
80            #include <math.h>
81            float (*funcptr) (float) = floorf;
82            float x;]],
83          [[x = funcptr(x) + floorf(x);]])],
84       [gl_cv_func_floorf_libm=])
85     if test "$gl_cv_func_floorf_libm" = "?"; then
86       save_LIBS="$LIBS"
87       LIBS="$LIBS -lm"
88       AC_LINK_IFELSE(
89         [AC_LANG_PROGRAM(
90            [[#ifndef __NO_MATH_INLINES
91              # define __NO_MATH_INLINES 1 /* for glibc */
92              #endif
93              #include <math.h>
94              float (*funcptr) (float) = floorf;
95              float x;]],
96            [[x = funcptr(x) + floorf(x);]])],
97         [gl_cv_func_floorf_libm="-lm"])
98       LIBS="$save_LIBS"
99     fi
100   ])
101   FLOORF_LIBM="$gl_cv_func_floorf_libm"
102 ])