Debian Codegraph @

m4/roundl.m4

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