Allow use of --avoid=extensions-aix.
[gnulib.git] / m4 / ceilf.m4
blobd27091c68d677e670e60b25ec7f4a09634028e26
1 # ceilf.m4
2 # serial 22
3 dnl Copyright (C) 2007, 2009-2024 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.
8 AC_DEFUN([gl_FUNC_CEILF],
10   m4_divert_text([DEFAULTS], [gl_ceilf_required=plain])
11   AC_REQUIRE([gl_MATH_H_DEFAULTS])
12   dnl Persuade glibc <math.h> to declare ceilf().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14   dnl Test whether ceilf() is declared.
15   AC_CHECK_DECLS([ceilf], , , [[#include <math.h>]])
16   if test "$ac_cv_have_decl_ceilf" = yes; then
17     dnl Test whether ceilf() can be used without libm.
18     gl_FUNC_CEILF_LIBS
19     if test "$CEILF_LIBM" = "?"; then
20       dnl Sun C 5.0 on Solaris declares ceilf() and has it in the system-wide
21       dnl libm.so, but not in the libm.so that the compiler uses.
22       REPLACE_CEILF=1
23     fi
24     m4_ifdef([gl_FUNC_CEILF_IEEE], [
25       if test $gl_ceilf_required = ieee && test $REPLACE_CEILF = 0; then
26         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
27         AC_CACHE_CHECK([whether ceilf works according to ISO C 99 with IEC 60559],
28           [gl_cv_func_ceilf_ieee],
29           [
30             saved_LIBS="$LIBS"
31             LIBS="$LIBS $CEILF_LIBM"
32             AC_RUN_IFELSE(
33               [AC_LANG_SOURCE([[
34 #ifndef __NO_MATH_INLINES
35 # define __NO_MATH_INLINES 1 /* for glibc */
36 #endif
37 #include <math.h>
38 ]gl_FLOAT_MINUS_ZERO_CODE[
39 ]gl_FLOAT_SIGNBIT_CODE[
40 static float dummy (float f) { return 0; }
41 int main (int argc, char *argv[])
43   float (* volatile my_ceilf) (float) = argc ? ceilf : dummy;
44   int result = 0;
45   /* Test whether ceilf (-0.0f) is -0.0f.  */
46   if (signbitf (minus_zerof) && !signbitf (my_ceilf (minus_zerof)))
47     result |= 1;
48   /* Test whether ceilf (-0.3f) is -0.0f.  */
49   if (signbitf (-0.3f) && !signbitf (my_ceilf (-0.3f)))
50     result |= 2;
51   return result;
53               ]])],
54               [gl_cv_func_ceilf_ieee=yes],
55               [gl_cv_func_ceilf_ieee=no],
56               [case "$host_os" in
57                                      # Guess yes on glibc systems.
58                  *-gnu* | gnu*)      gl_cv_func_ceilf_ieee="guessing yes" ;;
59                                      # Guess yes on musl systems.
60                  *-musl* | midipix*) gl_cv_func_ceilf_ieee="guessing yes" ;;
61                                      # Guess yes on native Windows.
62                  mingw* | windows*)  gl_cv_func_ceilf_ieee="guessing yes" ;;
63                                      # If we don't know, obey --enable-cross-guesses.
64                  *)                  gl_cv_func_ceilf_ieee="$gl_cross_guess_normal" ;;
65                esac
66               ])
67             LIBS="$saved_LIBS"
68           ])
69         case "$gl_cv_func_ceilf_ieee" in
70           *yes) ;;
71           *) REPLACE_CEILF=1 ;;
72         esac
73       fi
74     ])
75   else
76     HAVE_DECL_CEILF=0
77   fi
78   if test $HAVE_DECL_CEILF = 0 || test $REPLACE_CEILF = 1; then
79     dnl No libraries are needed to link lib/ceilf.c.
80     CEILF_LIBM=
81   fi
82   AC_SUBST([CEILF_LIBM])
85 # Determines the libraries needed to get the ceilf() function.
86 # Sets CEILF_LIBM.
87 AC_DEFUN([gl_FUNC_CEILF_LIBS],
89   gl_CACHE_VAL_SILENT([gl_cv_func_ceilf_libm], [
90     gl_cv_func_ceilf_libm=?
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            float (*funcptr) (float) = ceilf;
98            float x;]],
99          [[x = funcptr(x) + ceilf(x);]])],
100       [gl_cv_func_ceilf_libm=])
101     if test "$gl_cv_func_ceilf_libm" = "?"; then
102       saved_LIBS="$LIBS"
103       LIBS="$LIBS -lm"
104       AC_LINK_IFELSE(
105         [AC_LANG_PROGRAM(
106            [[#ifndef __NO_MATH_INLINES
107              # define __NO_MATH_INLINES 1 /* for glibc */
108              #endif
109              #include <math.h>
110              float (*funcptr) (float) = ceilf;
111              float x;]],
112            [[x = funcptr(x) + ceilf(x);]])],
113         [gl_cv_func_ceilf_libm="-lm"])
114       LIBS="$saved_LIBS"
115     fi
116   ])
117   CEILF_LIBM="$gl_cv_func_ceilf_libm"