3 dnl Copyright (C) 2007, 2010-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_TRUNC],
10 m4_divert_text([DEFAULTS], [gl_trunc_required=plain])
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 dnl Persuade glibc <math.h> to declare trunc().
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 dnl Test whether trunc() is declared.
15 AC_CHECK_DECLS([trunc], , , [[#include <math.h>]])
16 if test "$ac_cv_have_decl_trunc" = yes; then
17 dnl Test whether trunc() can be used without libm.
21 [[#ifndef __NO_MATH_INLINES
22 # define __NO_MATH_INLINES 1 /* for glibc */
25 double (*funcptr) (double) = trunc;
27 [[x = funcptr(x) + trunc(x);]])],
29 if test "$TRUNC_LIBM" = "?"; then
34 [[#ifndef __NO_MATH_INLINES
35 # define __NO_MATH_INLINES 1 /* for glibc */
38 double (*funcptr) (double) = trunc;
40 [[x = funcptr(x) + trunc(x);]])],
44 if test "$TRUNC_LIBM" = "?"; then
47 m4_ifdef([gl_FUNC_TRUNC_IEEE], [
48 if test $gl_trunc_required = ieee && test $REPLACE_TRUNC = 0; then
49 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
50 AC_CACHE_CHECK([whether trunc works according to ISO C 99 with IEC 60559],
51 [gl_cv_func_trunc_ieee],
54 LIBS="$LIBS $TRUNC_LIBM"
57 #ifndef __NO_MATH_INLINES
58 # define __NO_MATH_INLINES 1 /* for glibc */
61 ]gl_DOUBLE_MINUS_ZERO_CODE[
62 ]gl_DOUBLE_SIGNBIT_CODE[
63 static double dummy (double f) { return 0; }
64 int main (int argc, char *argv[])
66 double (* volatile my_trunc) (double) = argc ? trunc : dummy;
67 /* Test whether trunc (-0.0) is -0.0. */
68 if (signbitd (minus_zerod) && !signbitd (my_trunc (minus_zerod)))
73 [gl_cv_func_trunc_ieee=yes],
74 [gl_cv_func_trunc_ieee=no],
76 # Guess yes on glibc systems.
77 *-gnu* | gnu*) gl_cv_func_trunc_ieee="guessing yes" ;;
78 # Guess yes on musl systems.
79 *-musl* | midipix*) gl_cv_func_trunc_ieee="guessing yes" ;;
80 # Guess yes on native Windows.
81 mingw* | windows*) gl_cv_func_trunc_ieee="guessing yes" ;;
82 # If we don't know, obey --enable-cross-guesses.
83 *) gl_cv_func_trunc_ieee="$gl_cross_guess_normal" ;;
88 case "$gl_cv_func_trunc_ieee" in
97 if test $HAVE_DECL_TRUNC = 0 || test $REPLACE_TRUNC = 1; then
98 dnl No libraries are needed to link lib/trunc.c.
101 AC_SUBST([TRUNC_LIBM])