| 1 |
# ceil.m4 |
| 2 |
# serial 18 |
| 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_CEIL], |
| 10 |
[ |
| 11 |
m4_divert_text([DEFAULTS], [gl_ceil_required=plain]) |
| 12 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 13 |
dnl Test whether ceil() can be used without libm. |
| 14 |
gl_FUNC_CEIL_LIBS |
| 15 |
if test "$CEIL_LIBM" = "?"; then |
| 16 |
CEIL_LIBM= |
| 17 |
fi |
| 18 |
m4_ifdef([gl_FUNC_CEIL_IEEE], [ |
| 19 |
if test $gl_ceil_required = ieee && test $REPLACE_CEIL = 0; then |
| 20 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 21 |
AC_CACHE_CHECK([whether ceil works according to ISO C 99 with IEC 60559], |
| 22 |
[gl_cv_func_ceil_ieee], |
| 23 |
[ |
| 24 |
saved_LIBS="$LIBS" |
| 25 |
LIBS="$LIBS $CEIL_LIBM" |
| 26 |
AC_RUN_IFELSE( |
| 27 |
[AC_LANG_SOURCE([[ |
| 28 |
#ifndef __NO_MATH_INLINES |
| 29 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 30 |
#endif |
| 31 |
#include <math.h> |
| 32 |
]gl_DOUBLE_MINUS_ZERO_CODE[ |
| 33 |
]gl_DOUBLE_SIGNBIT_CODE[ |
| 34 |
static double dummy (double f) { return 0; } |
| 35 |
int main (int argc, char *argv[]) |
| 36 |
{ |
| 37 |
double (* volatile my_ceil) (double) = argc ? ceil : dummy; |
| 38 |
int result = 0; |
| 39 |
/* Test whether ceil (-0.0) is -0.0. */ |
| 40 |
if (signbitd (minus_zerod) && !signbitd (my_ceil (minus_zerod))) |
| 41 |
result |= 1; |
| 42 |
/* Test whether ceil (-0.3) is -0.0. */ |
| 43 |
if (signbitd (-0.3) && !signbitd (my_ceil (-0.3))) |
| 44 |
result |= 2; |
| 45 |
return result; |
| 46 |
} |
| 47 |
]])], |
| 48 |
[gl_cv_func_ceil_ieee=yes], |
| 49 |
[gl_cv_func_ceil_ieee=no], |
| 50 |
[case "$host_os" in |
| 51 |
# Guess yes on glibc systems. |
| 52 |
*-gnu* | gnu*) gl_cv_func_ceil_ieee="guessing yes" ;; |
| 53 |
# Guess yes on musl systems. |
| 54 |
*-musl* | midipix*) gl_cv_func_ceil_ieee="guessing yes" ;; |
| 55 |
# Guess yes on native Windows. |
| 56 |
mingw* | windows*) gl_cv_func_ceil_ieee="guessing yes" ;; |
| 57 |
# If we don't know, obey --enable-cross-guesses. |
| 58 |
*) gl_cv_func_ceil_ieee="$gl_cross_guess_normal" ;; |
| 59 |
esac |
| 60 |
]) |
| 61 |
LIBS="$saved_LIBS" |
| 62 |
]) |
| 63 |
case "$gl_cv_func_ceil_ieee" in |
| 64 |
*yes) ;; |
| 65 |
*) REPLACE_CEIL=1 ;; |
| 66 |
esac |
| 67 |
fi |
| 68 |
]) |
| 69 |
if test $REPLACE_CEIL = 1; then |
| 70 |
dnl No libraries are needed to link lib/ceil.c. |
| 71 |
CEIL_LIBM= |
| 72 |
fi |
| 73 |
AC_SUBST([CEIL_LIBM]) |
| 74 |
]) |
| 75 |
|
| 76 |
# Determines the libraries needed to get the ceil() function. |
| 77 |
# Sets CEIL_LIBM. |
| 78 |
AC_DEFUN([gl_FUNC_CEIL_LIBS], |
| 79 |
[ |
| 80 |
gl_CACHE_VAL_SILENT([gl_cv_func_ceil_libm], [ |
| 81 |
gl_cv_func_ceil_libm=? |
| 82 |
AC_LINK_IFELSE( |
| 83 |
[AC_LANG_PROGRAM( |
| 84 |
[[#ifndef __NO_MATH_INLINES |
| 85 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 86 |
#endif |
| 87 |
#include <math.h> |
| 88 |
double (*funcptr) (double) = ceil; |
| 89 |
double x;]], |
| 90 |
[[x = funcptr(x) + ceil(x);]])], |
| 91 |
[gl_cv_func_ceil_libm=]) |
| 92 |
if test "$gl_cv_func_ceil_libm" = "?"; then |
| 93 |
saved_LIBS="$LIBS" |
| 94 |
LIBS="$LIBS -lm" |
| 95 |
AC_LINK_IFELSE( |
| 96 |
[AC_LANG_PROGRAM( |
| 97 |
[[#ifndef __NO_MATH_INLINES |
| 98 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 99 |
#endif |
| 100 |
#include <math.h> |
| 101 |
double (*funcptr) (double) = ceil; |
| 102 |
double x;]], |
| 103 |
[[x = funcptr(x) + ceil(x);]])], |
| 104 |
[gl_cv_func_ceil_libm="-lm"]) |
| 105 |
LIBS="$saved_LIBS" |
| 106 |
fi |
| 107 |
]) |
| 108 |
CEIL_LIBM="$gl_cv_func_ceil_libm" |
| 109 |
]) |