git-merge-changelog: Simplify installation instructions.
[gnulib.git] / m4 / longlong.m4
blobebe9912cc5f13fd18dfb78e5d6baa6c75a68a74b
1 # longlong.m4
2 # serial 19
3 dnl Copyright (C) 1999-2007, 2009-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 dnl From Paul Eggert.
10 AC_PREREQ([2.62])
12 # Define HAVE_LONG_LONG_INT if 'long long int' works.
13 # This can be faster than what's in Autoconf 2.62 through 2.68.
15 # Note: If the type 'long long int' exists but is only 32 bits large
16 # (as on some very old compilers), HAVE_LONG_LONG_INT will not be
17 # defined. In this case you can treat 'long long int' like 'long int'.
19 AC_DEFUN([AC_TYPE_LONG_LONG_INT],
21   AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
22   AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
23      [ac_cv_type_long_long_int=yes
24       if test "x${ac_cv_prog_cc_c99-no}" = xno; then
25         ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int
26         if test $ac_cv_type_long_long_int = yes; then
27           dnl Catch a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
28           dnl If cross compiling, assume the bug is not important, since
29           dnl nobody cross compiles for this platform as far as we know.
30           AC_RUN_IFELSE(
31             [AC_LANG_PROGRAM(
32                [[#include <limits.h>
33                  #ifndef LLONG_MAX
34                  # define HALF \
35                           (1LL << (sizeof (long long int) * CHAR_BIT - 2))
36                  # define LLONG_MAX (HALF - 1 + HALF)
37                  #endif]],
38                [[long long int n = 1;
39                  int i;
40                  for (i = 0; ; i++)
41                    {
42                      long long int m = n << i;
43                      if (m >> i != n)
44                        return 1;
45                      if (LLONG_MAX / 2 < m)
46                        break;
47                    }
48                  return 0;]])],
49             [],
50             [ac_cv_type_long_long_int=no],
51             [:])
52         fi
53       fi])
54   if test $ac_cv_type_long_long_int = yes; then
55     AC_DEFINE([HAVE_LONG_LONG_INT], [1],
56       [Define to 1 if the system has the type 'long long int'.])
57   fi
60 # Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works.
61 # This can be faster than what's in Autoconf 2.62 through 2.68.
63 # Note: If the type 'unsigned long long int' exists but is only 32 bits
64 # large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT
65 # will not be defined. In this case you can treat 'unsigned long long int'
66 # like 'unsigned long int'.
68 AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
70   AC_CACHE_CHECK([for unsigned long long int],
71     [ac_cv_type_unsigned_long_long_int],
72     [ac_cv_type_unsigned_long_long_int=yes
73      if test "x${ac_cv_prog_cc_c99-no}" = xno; then
74        AC_LINK_IFELSE(
75          [_AC_TYPE_LONG_LONG_SNIPPET],
76          [],
77          [ac_cv_type_unsigned_long_long_int=no])
78      fi])
79   if test $ac_cv_type_unsigned_long_long_int = yes; then
80     AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
81       [Define to 1 if the system has the type 'unsigned long long int'.])
82   fi
85 # Expands to a C program that can be used to test for simultaneous support
86 # of 'long long' and 'unsigned long long'. We don't want to say that
87 # 'long long' is available if 'unsigned long long' is not, or vice versa,
88 # because too many programs rely on the symmetry between signed and unsigned
89 # integer types (excluding 'bool').
90 AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET],
92   AC_LANG_PROGRAM(
93     [[/* For now, do not test the preprocessor; as of 2007 there are too many
94          implementations with broken preprocessors.  Perhaps this can
95          be revisited in 2012.  In the meantime, code should not expect
96          #if to work with literals wider than 32 bits.  */
97       /* Test literals.  */
98       long long int ll = 9223372036854775807ll;
99       long long int nll = -9223372036854775807LL;
100       unsigned long long int ull = 18446744073709551615ULL;
101       /* Test constant expressions.   */
102       typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
103                      ? 1 : -1)];
104       typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
105                      ? 1 : -1)];
106       int i = 63;]],
107     [[/* Test availability of runtime routines for shift and division.  */
108       long long int llmax = 9223372036854775807ll;
109       unsigned long long int ullmax = 18446744073709551615ull;
110       return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
111               | (llmax / ll) | (llmax % ll)
112               | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
113               | (ullmax / ull) | (ullmax % ull));]])