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