2 dnl Copyright (C) 2007, 2009-2020 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 (* volatile 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* | gnu*) gl_cv_func_ceill_ieee="guessing yes" ;;
57 # Guess yes on musl systems.
58 *-musl*) gl_cv_func_ceill_ieee="guessing yes" ;;
59 # Guess yes on native Windows.
60 mingw*) gl_cv_func_ceill_ieee="guessing yes" ;;
61 # If we don't know, obey --enable-cross-guesses.
62 *) gl_cv_func_ceill_ieee="$gl_cross_guess_normal" ;;
67 case "$gl_cv_func_ceill_ieee" in
76 dnl On OpenBSD 5.6 the system's native ceill() is buggy:
77 dnl it returns '0' for small values. Test against this anomaly.
78 if test $REPLACE_CEILL = 0 ; then
79 AC_CACHE_CHECK([whether ceill() works],
80 [gl_cv_func_ceill_works],
86 long double d = 0.3L;]],
87 [[return (!(ceill (d) == 1)); ]])],
88 [gl_cv_func_ceill_works=yes],
89 [gl_cv_func_ceill_works=no],
91 openbsd*) gl_cv_func_ceill_works="guessing no" ;;
92 # Guess yes on native Windows.
93 mingw*) gl_cv_func_ceill_works="guessing yes" ;;
94 *) gl_cv_func_ceill_works="guessing yes" ;;
99 case "$gl_cv_func_ceill_works" in
101 *) REPLACE_CEILL=1 ;;
104 if test $HAVE_DECL_CEILL = 0 || test $REPLACE_CEILL = 1; then
105 dnl Find libraries needed to link lib/ceill.c.
106 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
107 AC_REQUIRE([gl_FUNC_CEIL])
108 CEILL_LIBM="$CEIL_LIBM"
113 AC_SUBST([CEILL_LIBM])
116 # Determines the libraries needed to get the ceill() function.
118 AC_DEFUN([gl_FUNC_CEILL_LIBS],
120 gl_CACHE_VAL_SILENT([gl_cv_func_ceill_libm], [
121 gl_cv_func_ceill_libm=?
124 [[#ifndef __NO_MATH_INLINES
125 # define __NO_MATH_INLINES 1 /* for glibc */
128 long double (*funcptr) (long double) = ceill;
130 [[x = funcptr(x) + ceill(x);]])],
131 [gl_cv_func_ceill_libm=])
132 if test "$gl_cv_func_ceill_libm" = "?"; then
137 [[#ifndef __NO_MATH_INLINES
138 # define __NO_MATH_INLINES 1 /* for glibc */
141 long double (*funcptr) (long double) = ceill;
143 [[x = funcptr(x) + ceill(x);]])],
144 [gl_cv_func_ceill_libm="-lm"])
148 CEILL_LIBM="$gl_cv_func_ceill_libm"