2 dnl Copyright (C) 2007, 2009-2017 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.
7 AC_DEFUN([gl_FUNC_CEILL],
9 m4_divert_text([DEFAULTS], [gl_ceill_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
14 dnl Persuade glibc <math.h> to declare ceill().
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17 dnl Test whether ceill() is declared.
18 AC_CHECK_DECLS([ceill], , , [[#include <math.h>]])
19 if test "$ac_cv_have_decl_ceill" = yes; then
20 dnl Test whether ceill() can be used without libm.
22 if test "$CEILL_LIBM" = "?"; then
23 dnl Sun C 5.0 on Solaris declares ceill() and has it in the system-wide
24 dnl libm.so, but not in the libm.so that the compiler uses.
27 m4_ifdef([gl_FUNC_CEILL_IEEE], [
28 if test $gl_ceill_required = ieee && test $REPLACE_CEILL = 0; then
29 AC_CACHE_CHECK([whether ceill works according to ISO C 99 with IEC 60559],
30 [gl_cv_func_ceill_ieee],
33 LIBS="$LIBS $CEILL_LIBM"
36 #ifndef __NO_MATH_INLINES
37 # define __NO_MATH_INLINES 1 /* for glibc */
40 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
41 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
42 static long double dummy (long double f) { return 0; }
43 int main (int argc, char *argv[])
45 long double (*my_ceill) (long double) = argc ? ceill : dummy;
46 /* Test whether ceill (-0.3L) is -0.0L. */
47 if (signbitl (minus_zerol) && !signbitl (my_ceill (-0.3L)))
52 [gl_cv_func_ceill_ieee=yes],
53 [gl_cv_func_ceill_ieee=no],
55 # Guess yes on glibc systems.
56 *-gnu*) gl_cv_func_ceill_ieee="guessing yes" ;;
57 # Guess yes on native Windows.
58 mingw*) gl_cv_func_ceill_ieee="guessing yes" ;;
59 # If we don't know, assume the worst.
60 *) gl_cv_func_ceill_ieee="guessing no" ;;
65 case "$gl_cv_func_ceill_ieee" in
74 dnl On OpenBSD5.6 the system's native ceill() is buggy:
75 dnl it returns '0' for small values. Test for this anomaly.
76 if test $REPLACE_CEILL = 0 ; then
77 AC_CACHE_CHECK([whether ceill() breaks with small values],
78 [gl_cv_func_ceill_buggy],
85 long double d = 0.3L;]],
86 [[return (!(ceill (d) == 1)); ]])],
87 [gl_cv_func_ceill_buggy=no], [gl_cv_func_ceill_buggy=yes],
89 openbsd*) gl_cv_func_ceill_buggy="guessing yes" ;;
90 # Guess no on native Windows.
91 mingw*) gl_cv_func_ceill_buggy="guessing no" ;;
92 *) gl_cv_func_ceill_buggy="guessing no" ;;
97 case "$gl_cv_func_ceill_buggy" in
102 if test $HAVE_DECL_CEILL = 0 || test $REPLACE_CEILL = 1; then
103 dnl Find libraries needed to link lib/ceill.c.
104 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
105 AC_REQUIRE([gl_FUNC_CEIL])
106 CEILL_LIBM="$CEIL_LIBM"
111 AC_SUBST([CEILL_LIBM])
114 # Determines the libraries needed to get the ceill() function.
116 AC_DEFUN([gl_FUNC_CEILL_LIBS],
118 gl_CACHE_VAL_SILENT([gl_cv_func_ceill_libm], [
119 gl_cv_func_ceill_libm=?
122 [[#ifndef __NO_MATH_INLINES
123 # define __NO_MATH_INLINES 1 /* for glibc */
126 long double (*funcptr) (long double) = ceill;
128 [[x = funcptr(x) + ceill(x);]])],
129 [gl_cv_func_ceill_libm=])
130 if test "$gl_cv_func_ceill_libm" = "?"; then
135 [[#ifndef __NO_MATH_INLINES
136 # define __NO_MATH_INLINES 1 /* for glibc */
139 long double (*funcptr) (long double) = ceill;
141 [[x = funcptr(x) + ceill(x);]])],
142 [gl_cv_func_ceill_libm="-lm"])
146 CEILL_LIBM="$gl_cv_func_ceill_libm"