| 1 |
# ceill.m4 |
| 2 |
# serial 25 |
| 3 |
dnl Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_CEILL], |
| 10 |
[ |
| 11 |
m4_divert_text([DEFAULTS], [gl_ceill_required=plain]) |
| 12 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 13 |
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 14 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 15 |
|
| 16 |
dnl Persuade glibc <math.h> to declare ceill(). |
| 17 |
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 18 |
|
| 19 |
dnl Test whether ceill() is declared. |
| 20 |
AC_CHECK_DECLS([ceill], , , [[#include <math.h>]]) |
| 21 |
if test "$ac_cv_have_decl_ceill" = yes; then |
| 22 |
dnl Test whether ceill() can be used without libm. |
| 23 |
gl_FUNC_CEILL_LIBS |
| 24 |
if test "$CEILL_LIBM" = "?"; then |
| 25 |
dnl Sun C 5.0 on Solaris declares ceill() and has it in the system-wide |
| 26 |
dnl libm.so, but not in the libm.so that the compiler uses. |
| 27 |
REPLACE_CEILL=1 |
| 28 |
fi |
| 29 |
m4_ifdef([gl_FUNC_CEILL_IEEE], [ |
| 30 |
if test $gl_ceill_required = ieee && test $REPLACE_CEILL = 0; then |
| 31 |
AC_CACHE_CHECK([whether ceill works according to ISO C 99 with IEC 60559], |
| 32 |
[gl_cv_func_ceill_ieee], |
| 33 |
[ |
| 34 |
saved_LIBS="$LIBS" |
| 35 |
LIBS="$LIBS $CEILL_LIBM" |
| 36 |
AC_RUN_IFELSE( |
| 37 |
[AC_LANG_SOURCE([[ |
| 38 |
#ifndef __NO_MATH_INLINES |
| 39 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 40 |
#endif |
| 41 |
#include <math.h> |
| 42 |
]gl_LONG_DOUBLE_MINUS_ZERO_CODE[ |
| 43 |
]gl_LONG_DOUBLE_SIGNBIT_CODE[ |
| 44 |
static long double dummy (long double f) { return 0; } |
| 45 |
int main (int argc, char *argv[]) |
| 46 |
{ |
| 47 |
long double (* volatile my_ceill) (long double) = argc ? ceill : dummy; |
| 48 |
/* Test whether ceill (-0.3L) is -0.0L. */ |
| 49 |
if (signbitl (minus_zerol) && !signbitl (my_ceill (-0.3L))) |
| 50 |
return 1; |
| 51 |
return 0; |
| 52 |
} |
| 53 |
]])], |
| 54 |
[gl_cv_func_ceill_ieee=yes], |
| 55 |
[gl_cv_func_ceill_ieee=no], |
| 56 |
[case "$host_os" in |
| 57 |
# Guess yes on glibc systems. |
| 58 |
*-gnu* | gnu*) gl_cv_func_ceill_ieee="guessing yes" ;; |
| 59 |
# Guess yes on musl systems. |
| 60 |
*-musl* | midipix*) gl_cv_func_ceill_ieee="guessing yes" ;; |
| 61 |
# Guess yes on native Windows. |
| 62 |
mingw* | windows*) gl_cv_func_ceill_ieee="guessing yes" ;; |
| 63 |
# If we don't know, obey --enable-cross-guesses. |
| 64 |
*) gl_cv_func_ceill_ieee="$gl_cross_guess_normal" ;; |
| 65 |
esac |
| 66 |
]) |
| 67 |
LIBS="$saved_LIBS" |
| 68 |
]) |
| 69 |
case "$gl_cv_func_ceill_ieee" in |
| 70 |
*yes) ;; |
| 71 |
*) REPLACE_CEILL=1 ;; |
| 72 |
esac |
| 73 |
fi |
| 74 |
]) |
| 75 |
else |
| 76 |
HAVE_DECL_CEILL=0 |
| 77 |
fi |
| 78 |
dnl On OpenBSD 5.6 the system's native ceill() is buggy: |
| 79 |
dnl it returns '0' for small values. Test against this anomaly. |
| 80 |
if test $REPLACE_CEILL = 0 ; then |
| 81 |
AC_CACHE_CHECK([whether ceill() works], |
| 82 |
[gl_cv_func_ceill_works], |
| 83 |
[saved_LIBS="$LIBS" |
| 84 |
LIBS="$CEILL_LIBM" |
| 85 |
AC_RUN_IFELSE( |
| 86 |
[AC_LANG_PROGRAM( |
| 87 |
[[#include <math.h> |
| 88 |
long double d = 0.3L;]], |
| 89 |
[[return (!(ceill (d) == 1)); ]])], |
| 90 |
[gl_cv_func_ceill_works=yes], |
| 91 |
[gl_cv_func_ceill_works=no], |
| 92 |
[case "$host_os" in |
| 93 |
openbsd*) gl_cv_func_ceill_works="guessing no" ;; |
| 94 |
# Guess yes on native Windows. |
| 95 |
mingw* | windows*) gl_cv_func_ceill_works="guessing yes" ;; |
| 96 |
*) gl_cv_func_ceill_works="guessing yes" ;; |
| 97 |
esac |
| 98 |
]) |
| 99 |
LIBS="$saved_LIBS" |
| 100 |
]) |
| 101 |
case "$gl_cv_func_ceill_works" in |
| 102 |
*yes) ;; |
| 103 |
*) REPLACE_CEILL=1 ;; |
| 104 |
esac |
| 105 |
fi |
| 106 |
if test $HAVE_DECL_CEILL = 0 || test $REPLACE_CEILL = 1; then |
| 107 |
dnl Find libraries needed to link lib/ceill.c. |
| 108 |
if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then |
| 109 |
AC_REQUIRE([gl_FUNC_CEIL]) |
| 110 |
CEILL_LIBM="$CEIL_LIBM" |
| 111 |
else |
| 112 |
CEILL_LIBM= |
| 113 |
fi |
| 114 |
fi |
| 115 |
AC_SUBST([CEILL_LIBM]) |
| 116 |
]) |
| 117 |
|
| 118 |
# Determines the libraries needed to get the ceill() function. |
| 119 |
# Sets CEILL_LIBM. |
| 120 |
AC_DEFUN([gl_FUNC_CEILL_LIBS], |
| 121 |
[ |
| 122 |
gl_CACHE_VAL_SILENT([gl_cv_func_ceill_libm], [ |
| 123 |
gl_cv_func_ceill_libm=? |
| 124 |
AC_LINK_IFELSE( |
| 125 |
[AC_LANG_PROGRAM( |
| 126 |
[[#ifndef __NO_MATH_INLINES |
| 127 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 128 |
#endif |
| 129 |
#include <math.h> |
| 130 |
long double (*funcptr) (long double) = ceill; |
| 131 |
long double x;]], |
| 132 |
[[x = funcptr(x) + ceill(x);]])], |
| 133 |
[gl_cv_func_ceill_libm=]) |
| 134 |
if test "$gl_cv_func_ceill_libm" = "?"; then |
| 135 |
saved_LIBS="$LIBS" |
| 136 |
LIBS="$LIBS -lm" |
| 137 |
AC_LINK_IFELSE( |
| 138 |
[AC_LANG_PROGRAM( |
| 139 |
[[#ifndef __NO_MATH_INLINES |
| 140 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 141 |
#endif |
| 142 |
#include <math.h> |
| 143 |
long double (*funcptr) (long double) = ceill; |
| 144 |
long double x;]], |
| 145 |
[[x = funcptr(x) + ceill(x);]])], |
| 146 |
[gl_cv_func_ceill_libm="-lm"]) |
| 147 |
LIBS="$saved_LIBS" |
| 148 |
fi |
| 149 |
]) |
| 150 |
CEILL_LIBM="$gl_cv_func_ceill_libm" |
| 151 |
]) |