glob.c: Silence warning about void pointer arithmetic
[gnulib.git] / m4 / truncl.m4
blob5fd0411c18c51028e4e1b7886c285b6050355464
1 # truncl.m4 serial 12
2 dnl Copyright (C) 2007-2008, 2010-2017 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.
21     TRUNCL_LIBM=?
22     AC_LINK_IFELSE(
23       [AC_LANG_PROGRAM(
24          [[#ifndef __NO_MATH_INLINES
25            # define __NO_MATH_INLINES 1 /* for glibc */
26            #endif
27            #include <math.h>
28            long double x;]],
29          [[x = truncl(x);]])],
30       [TRUNCL_LIBM=])
31     if test "$TRUNCL_LIBM" = "?"; then
32       save_LIBS="$LIBS"
33       LIBS="$LIBS -lm"
34       AC_LINK_IFELSE(
35         [AC_LANG_PROGRAM(
36            [[#ifndef __NO_MATH_INLINES
37              # define __NO_MATH_INLINES 1 /* for glibc */
38              #endif
39              #include <math.h>
40              long double x;]],
41            [[x = truncl(x);]])],
42         [TRUNCL_LIBM="-lm"])
43       LIBS="$save_LIBS"
44     fi
45     if test "$TRUNCL_LIBM" = "?"; then
46       TRUNCL_LIBM=
47     fi
48     dnl Test whether truncl() works. It crashes on OSF/1 4.0d.
49     save_LIBS="$LIBS"
50     LIBS="$LIBS $TRUNCL_LIBM"
51     AC_CACHE_CHECK([whether truncl works], [gl_cv_func_truncl_works],
52       [
53         AC_RUN_IFELSE(
54           [AC_LANG_SOURCE([[
55 #include <math.h>
56 long double x;
57 int main()
59   x = truncl (0.0L);
60   return 0;
61 }]])],
62           [gl_cv_func_truncl_works=yes],
63           [gl_cv_func_truncl_works=no],
64           [case "$host_os" in
65              osf4*)  gl_cv_func_truncl_works="guessing no" ;;
66                      # Guess yes on native Windows.
67              mingw*) gl_cv_func_truncl_works="guessing yes" ;;
68              *)      gl_cv_func_truncl_works="guessing yes" ;;
69            esac
70           ])
71       ])
72     LIBS="$save_LIBS"
73     case "$gl_cv_func_truncl_works" in
74       *yes) ;;
75       *) REPLACE_TRUNCL=1 ;;
76     esac
77     m4_ifdef([gl_FUNC_TRUNCL_IEEE], [
78       if test $gl_truncl_required = ieee && test $REPLACE_TRUNCL = 0; then
79         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
80         AC_CACHE_CHECK([whether truncl works according to ISO C 99 with IEC 60559],
81           [gl_cv_func_truncl_ieee],
82           [
83             save_LIBS="$LIBS"
84             LIBS="$LIBS $TRUNCL_LIBM"
85             AC_RUN_IFELSE(
86               [AC_LANG_SOURCE([[
87 #ifndef __NO_MATH_INLINES
88 # define __NO_MATH_INLINES 1 /* for glibc */
89 #endif
90 #include <math.h>
91 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
92 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
93 static long double dummy (long double f) { return 0; }
94 int main (int argc, char *argv[])
96   long double (*my_truncl) (long double) = argc ? truncl : dummy;
97   /* Test whether truncl (-0.3L) is -0.0L.  */
98   if (signbitl (minus_zerol) && !signbitl (my_truncl (-0.3L)))
99     return 1;
100   return 0;
102               ]])],
103               [gl_cv_func_truncl_ieee=yes],
104               [gl_cv_func_truncl_ieee=no],
105               [case "$host_os" in
106                          # Guess yes on glibc systems.
107                  *-gnu*) gl_cv_func_truncl_ieee="guessing yes" ;;
108                          # Guess yes on native Windows.
109                  mingw*) gl_cv_func_truncl_ieee="guessing yes" ;;
110                          # If we don't know, assume the worst.
111                  *)      gl_cv_func_truncl_ieee="guessing no" ;;
112                esac
113               ])
114             LIBS="$save_LIBS"
115           ])
116         case "$gl_cv_func_truncl_ieee" in
117           *yes) ;;
118           *) REPLACE_TRUNCL=1 ;;
119         esac
120       fi
121     ])
122   else
123     HAVE_DECL_TRUNCL=0
124   fi
125   if test $HAVE_DECL_TRUNCL = 0 || test $REPLACE_TRUNCL = 1; then
126     dnl Find libraries needed to link lib/truncl.c.
127     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
128       AC_REQUIRE([gl_FUNC_TRUNC])
129       TRUNCL_LIBM="$TRUNC_LIBM"
130     else
131       TRUNCL_LIBM=
132     fi
133   fi
134   AC_SUBST([TRUNCL_LIBM])