Do the Windows oldnames workaround through the C++ GNULIB_NAMESPACE.
[gnulib.git] / m4 / roundl.m4
blobbe70e671f5a3d970e0dbdc4cb73a3013f506743a
1 # roundl.m4 serial 20
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_ROUNDL],
9   m4_divert_text([DEFAULTS], [gl_roundl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
13   dnl Persuade glibc <math.h> to declare roundl().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16   gl_CHECK_MATH_LIB([ROUNDL_LIBM], [x = roundl (x);],
17     [extern
18      #ifdef __cplusplus
19      "C"
20      #endif
21      long double roundl (long double);
22     ])
23   if test "$ROUNDL_LIBM" != missing; then
24     HAVE_ROUNDL=1
25     dnl Also check whether it's declared.
26     dnl IRIX 6.5 has roundl() in libm but doesn't declare it in <math.h>.
27     AC_CHECK_DECLS([roundl], , [HAVE_DECL_ROUNDL=0], [[#include <math.h>]])
29     m4_ifdef([gl_FUNC_ROUNDL_IEEE], [
30       if test $gl_roundl_required = ieee && test $REPLACE_ROUNDL = 0; then
31         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
32         AC_CACHE_CHECK([whether roundl works according to ISO C 99 with IEC 60559],
33           [gl_cv_func_roundl_ieee],
34           [
35             save_LIBS="$LIBS"
36             LIBS="$LIBS $ROUNDL_LIBM"
37             AC_RUN_IFELSE(
38               [AC_LANG_SOURCE([[
39 #ifndef __NO_MATH_INLINES
40 # define __NO_MATH_INLINES 1 /* for glibc */
41 #endif
42 #include <math.h>
43 extern
44 #ifdef __cplusplus
45 "C"
46 #endif
47 long double roundl (long double);
48 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
49 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
50 static long double dummy (long double f) { return 0; }
51 int main (int argc, char *argv[])
53   long double (* volatile my_roundl) (long double) = argc ? roundl : dummy;
54   int result = 0;
55   /* Test whether roundl (-0.0L) is -0.0L.  */
56   if (signbitl (minus_zerol) && !signbitl (my_roundl (minus_zerol)))
57     result |= 1;
58   /* Test whether roundl (-0.3L) is -0.0L.  */
59   if (signbitl (-0.3L) && !signbitl (my_roundl (-0.3L)))
60     result |= 2;
61   return result;
63               ]])],
64               [gl_cv_func_roundl_ieee=yes],
65               [gl_cv_func_roundl_ieee=no],
66               [case "$host_os" in
67                                 # Guess yes on glibc systems.
68                  *-gnu* | gnu*) gl_cv_func_roundl_ieee="guessing yes" ;;
69                                 # Guess yes on musl systems.
70                  *-musl*)       gl_cv_func_roundl_ieee="guessing yes" ;;
71                                 # Guess yes on native Windows.
72                  mingw*)        gl_cv_func_roundl_ieee="guessing yes" ;;
73                                 # If we don't know, obey --enable-cross-guesses.
74                  *)             gl_cv_func_roundl_ieee="$gl_cross_guess_normal" ;;
75                esac
76               ])
77             LIBS="$save_LIBS"
78           ])
79         case "$gl_cv_func_roundl_ieee" in
80           *yes) ;;
81           *) REPLACE_ROUNDL=1 ;;
82         esac
83       fi
84     ])
85   else
86     HAVE_ROUNDL=0
87     HAVE_DECL_ROUNDL=0
88   fi
89   if test $HAVE_ROUNDL = 0 || test $REPLACE_ROUNDL = 1; then
90     dnl Find libraries needed to link lib/roundl.c.
91     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
92       AC_REQUIRE([gl_FUNC_ROUND])
93       ROUNDL_LIBM="$ROUND_LIBM"
94     else
95       AC_CHECK_DECLS([ceill, floorl], , , [[#include <math.h>]])
96       if test "$ac_cv_have_decl_floorl" = yes \
97          && test "$ac_cv_have_decl_ceill" = yes; then
98         gl_FUNC_FLOORL_LIBS
99         gl_FUNC_CEILL_LIBS
100         if test "$FLOORL_LIBM" != '?' && test "$CEILL_LIBM" != '?'; then
101           AC_DEFINE([HAVE_FLOORL_AND_CEILL], [1],
102             [Define if the both the floorl() and ceill() functions exist.])
103           ROUNDL_LIBM=
104           dnl Append $FLOORL_LIBM to ROUNDL_LIBM, avoiding gratuitous duplicates.
105           case " $ROUNDL_LIBM " in
106             *" $FLOORL_LIBM "*) ;;
107             *) ROUNDL_LIBM="$ROUNDL_LIBM $FLOORL_LIBM" ;;
108           esac
109           dnl Append $CEILL_LIBM to ROUNDL_LIBM, avoiding gratuitous duplicates.
110           case " $ROUNDL_LIBM " in
111             *" $CEILL_LIBM "*) ;;
112             *) ROUNDL_LIBM="$ROUNDL_LIBM $CEILL_LIBM" ;;
113           esac
114         else
115           ROUNDL_LIBM=
116         fi
117       else
118         ROUNDL_LIBM=
119       fi
120     fi
121   fi
122   AC_SUBST([ROUNDL_LIBM])