Debian Codegraph @

m4/trunc.m4

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