2 dnl Copyright (C) 2007-2008, 2010-2012 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_TRUNCL],
9 m4_divert_text([DEFAULTS], [gl_truncl_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
14 dnl Persuade glibc <math.h> to declare truncl().
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17 dnl Test whether truncl() is declared.
18 AC_CHECK_DECLS([truncl], , , [[#include <math.h>]])
19 if test "$ac_cv_have_decl_truncl" = yes; then
20 dnl Test whether truncl() can be used without libm.
24 [[#ifndef __NO_MATH_INLINES
25 # define __NO_MATH_INLINES 1 /* for glibc */
31 if test "$TRUNCL_LIBM" = "?"; then
36 [[#ifndef __NO_MATH_INLINES
37 # define __NO_MATH_INLINES 1 /* for glibc */
45 if test "$TRUNCL_LIBM" = "?"; then
48 dnl Test whether truncl() works. It crashes on OSF/1 4.0d.
50 LIBS="$LIBS $TRUNCL_LIBM"
51 AC_CACHE_CHECK([whether truncl works], [gl_cv_func_truncl_works],
62 [gl_cv_func_truncl_works=yes],
63 [gl_cv_func_truncl_works=no],
65 osf4*) gl_cv_func_truncl_works="guessing no";;
66 *) gl_cv_func_truncl_works="guessing yes";;
71 case "$gl_cv_func_truncl_works" in
73 *) REPLACE_TRUNCL=1 ;;
75 m4_ifdef([gl_FUNC_TRUNCL_IEEE], [
76 if test $gl_truncl_required = ieee && test $REPLACE_TRUNCL = 0; then
77 AC_CACHE_CHECK([whether truncl works according to ISO C 99 with IEC 60559],
78 [gl_cv_func_truncl_ieee],
81 LIBS="$LIBS $TRUNCL_LIBM"
84 #ifndef __NO_MATH_INLINES
85 # define __NO_MATH_INLINES 1 /* for glibc */
88 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
89 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
90 static long double dummy (long double f) { return 0; }
91 int main (int argc, char *argv[])
93 long double (*my_truncl) (long double) = argc ? truncl : dummy;
94 /* Test whether truncl (-0.3L) is -0.0L. */
95 if (signbitl (minus_zerol) && !signbitl (my_truncl (-0.3L)))
100 [gl_cv_func_truncl_ieee=yes],
101 [gl_cv_func_truncl_ieee=no],
102 [gl_cv_func_truncl_ieee="guessing no"])
105 case "$gl_cv_func_truncl_ieee" in
107 *) REPLACE_TRUNCL=1 ;;
114 if test $HAVE_DECL_TRUNCL = 0 || test $REPLACE_TRUNCL = 1; then
115 dnl Find libraries needed to link lib/truncl.c.
116 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
117 AC_REQUIRE([gl_FUNC_TRUNC])
118 TRUNCL_LIBM="$TRUNC_LIBM"
123 AC_SUBST([TRUNCL_LIBM])