ceilf.m4 3.66 KB
Newer Older
1
# ceilf.m4 serial 14
Paul Eggert's avatar
Paul Eggert committed
2
dnl Copyright (C) 2007, 2009-2016 Free Software Foundation, Inc.
Bruno Haible's avatar
Bruno Haible committed
3 4 5 6 7 8
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_FUNC_CEILF],
[
Bruno Haible's avatar
Bruno Haible committed
9
  m4_divert_text([DEFAULTS], [gl_ceilf_required=plain])
Bruno Haible's avatar
Bruno Haible committed
10 11 12 13
  AC_REQUIRE([gl_MATH_H_DEFAULTS])
  dnl Persuade glibc <math.h> to declare ceilf().
  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  dnl Test whether ceilf() is declared.
14
  AC_CHECK_DECLS([ceilf], , , [[#include <math.h>]])
Bruno Haible's avatar
Bruno Haible committed
15 16
  if test "$ac_cv_have_decl_ceilf" = yes; then
    dnl Test whether ceilf() can be used without libm.
17 18
    gl_FUNC_CEILF_LIBS
    if test "$CEILF_LIBM" = "?"; then
19 20 21
      dnl Sun C 5.0 on Solaris declares ceilf() and has it in the system-wide
      dnl libm.so, but not in the libm.so that the compiler uses.
      REPLACE_CEILF=1
22
    fi
Bruno Haible's avatar
Bruno Haible committed
23 24
    m4_ifdef([gl_FUNC_CEILF_IEEE], [
      if test $gl_ceilf_required = ieee && test $REPLACE_CEILF = 0; then
25
        AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Bruno Haible's avatar
Bruno Haible committed
26 27 28 29 30 31 32 33 34 35 36 37 38
        AC_CACHE_CHECK([whether ceilf works according to ISO C 99 with IEC 60559],
          [gl_cv_func_ceilf_ieee],
          [
            save_LIBS="$LIBS"
            LIBS="$LIBS $CEILF_LIBM"
            AC_RUN_IFELSE(
              [AC_LANG_SOURCE([[
#ifndef __NO_MATH_INLINES
# define __NO_MATH_INLINES 1 /* for glibc */
#endif
#include <math.h>
]gl_FLOAT_MINUS_ZERO_CODE[
]gl_FLOAT_SIGNBIT_CODE[
39 40
static float dummy (float f) { return 0; }
int main (int argc, char *argv[])
Bruno Haible's avatar
Bruno Haible committed
41
{
42
  float (*my_ceilf) (float) = argc ? ceilf : dummy;
43
  int result = 0;
Bruno Haible's avatar
Bruno Haible committed
44
  /* Test whether ceilf (-0.0f) is -0.0f.  */
45
  if (signbitf (minus_zerof) && !signbitf (my_ceilf (minus_zerof)))
46 47
    result |= 1;
  /* Test whether ceilf (-0.3f) is -0.0f.  */
48
  if (signbitf (-0.3f) && !signbitf (my_ceilf (-0.3f)))
49 50
    result |= 2;
  return result;
Bruno Haible's avatar
Bruno Haible committed
51 52 53 54
}
              ]])],
              [gl_cv_func_ceilf_ieee=yes],
              [gl_cv_func_ceilf_ieee=no],
55 56 57 58 59 60 61
              [case "$host_os" in
                         # Guess yes on glibc systems.
                 *-gnu*) gl_cv_func_ceilf_ieee="guessing yes" ;;
                         # If we don't know, assume the worst.
                 *)      gl_cv_func_ceilf_ieee="guessing no" ;;
               esac
              ])
Bruno Haible's avatar
Bruno Haible committed
62 63 64 65 66 67 68 69
            LIBS="$save_LIBS"
          ])
        case "$gl_cv_func_ceilf_ieee" in
          *yes) ;;
          *) REPLACE_CEILF=1 ;;
        esac
      fi
    ])
70
  else
71
    HAVE_DECL_CEILF=0
72
  fi
73
  if test $HAVE_DECL_CEILF = 0 || test $REPLACE_CEILF = 1; then
74
    dnl No libraries are needed to link lib/ceilf.c.
75 76 77 78 79 80 81 82 83
    CEILF_LIBM=
  fi
  AC_SUBST([CEILF_LIBM])
])

# Determines the libraries needed to get the ceilf() function.
# Sets CEILF_LIBM.
AC_DEFUN([gl_FUNC_CEILF_LIBS],
[
84
  gl_CACHE_VAL_SILENT([gl_cv_func_ceilf_libm], [
85
    gl_cv_func_ceilf_libm=?
86 87 88 89 90 91
    AC_LINK_IFELSE(
      [AC_LANG_PROGRAM(
         [[#ifndef __NO_MATH_INLINES
           # define __NO_MATH_INLINES 1 /* for glibc */
           #endif
           #include <math.h>
92
           float (*funcptr) (float) = ceilf;
93
           float x;]],
94
         [[x = funcptr(x) + ceilf(x);]])],
95 96
      [gl_cv_func_ceilf_libm=])
    if test "$gl_cv_func_ceilf_libm" = "?"; then
Bruno Haible's avatar
Bruno Haible committed
97 98
      save_LIBS="$LIBS"
      LIBS="$LIBS -lm"
99 100 101 102 103 104
      AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
           [[#ifndef __NO_MATH_INLINES
             # define __NO_MATH_INLINES 1 /* for glibc */
             #endif
             #include <math.h>
105
             float (*funcptr) (float) = ceilf;
106
             float x;]],
107
           [[x = funcptr(x) + ceilf(x);]])],
108
        [gl_cv_func_ceilf_libm="-lm"])
Bruno Haible's avatar
Bruno Haible committed
109 110
      LIBS="$save_LIBS"
    fi
111
  ])
112
  CEILF_LIBM="$gl_cv_func_ceilf_libm"
Bruno Haible's avatar
Bruno Haible committed
113
])