fix doc example typo
[boost.git] / boost / detail / extended_integer.hpp
blobc69636c73b1e3bda5886ee75a5c6aaf7c4535c84
1 // Boost detail/extended_integer.hpp header file ----------------------------//
3 // (C) Copyright Daryle Walker 2008. Distributed under the Boost Software
4 // License, Version 1.0. (See the accompanying file LICENSE_1_0.txt or a copy
5 // at <http://www.boost.org/LICENSE_1_0.txt>.)
7 // Encapsulates the double-long and __int64 type families as a single family,
8 // as they are mutually exclusive.
10 /** \file
11 \brief Common definition of extended integer types.
13 Instead of other Boost headers making separate \#defines for the double-long
14 and __int64 type families, since they're mutually exclusive, make a single
15 set of types and macros for the family that exists (if either).
18 #ifndef BOOST_DETAIL_EXTENDED_INTEGER_HPP
19 #define BOOST_DETAIL_EXTENDED_INTEGER_HPP
21 #include <boost/config.hpp> // for BOOST_HAS_LONG_LONG and BOOST_HAS_MS_INT64
23 #include <climits> // for CHAR_BIT, etc.
26 namespace boost
28 namespace detail
32 // Extended integer type macro and alias definitions -----------------------//
34 // (Unsigned) long long family
35 #ifdef BOOST_HAS_LONG_LONG
37 // Existence
38 #define BOOST_HAS_XINT 1
40 // Extents
41 #ifdef ULLONG_MAX
42 #define BOOST_XINT_MAX LLONG_MAX
43 #define BOOST_XINT_MIN LLONG_MIN
44 #define BOOST_UXINT_MAX ULLONG_MAX
45 #elif defined(ULONG_LONG_MAX)
46 #define BOOST_XINT_MAX LONG_LONG_MAX
47 #define BOOST_XINT_MIN LONG_LONG_MIN
48 #define BOOST_UXINT_MAX ULONG_LONG_MAX
49 #elif defined(ULONGLONG_MAX)
50 #define BOOST_XINT_MAX LONGLONG_MAX
51 #define BOOST_XINT_MIN LONGLONG_MIN
52 #define BOOST_UXINT_MAX ULONGLONG_MAX
53 #elif defined(_LLONG_MAX) && defined(_C2)
54 #define BOOST_XINT_MAX _LLONG_MAX
55 #define BOOST_XINT_MIN (-_LLONG_MAX - _C2)
56 #define BOOST_UXINT_MAX _ULLONG_MAX
57 #else // guess
58 // Sometimes we get the double-long types without the corresponding constants,
59 // e.g. GCC in "-ansi" mode. In this case, we'll just have to work out the
60 // values ourselves. (Here we assume a two's complement representation.)
61 #define BOOST_XINT_MIN (1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1))
62 #define BOOST_XINT_MAX (~ BOOST_XINT_MIN)
63 #define BOOST_UXINT_MAX (~ 0uLL)
64 #endif
66 // Types
67 typedef ::boost:: long_long_type xint_t;
68 typedef ::boost::ulong_long_type uxint_t;
70 // (Unsigned) __int64 family
71 #elif defined(BOOST_HAS_MS_INT64)
73 // Existence
74 #define BOOST_HAS_XINT 1
76 // Extents
77 #ifdef _UI64_MAX
78 #define BOOST_XINT_MAX _I64_MAX
79 #define BOOST_XINT_MIN _I64_MIN
80 #define BOOST_UXINT_MAX _UI64_MAX
81 #else // guess
82 // The types are exactly 2's-compl. 64-bit, so we'll enter the values directly.
83 #define BOOST_XINT_MAX 0x7FFFFFFFFFFFFFFFi64
84 #define BOOST_XINT_MIN 0x8000000000000000i64
85 #define BOOST_UXINT_MAX 0xFFFFFFFFFFFFFFFFui64
86 #endif
88 // Types
89 typedef __int64 xint_t;
90 typedef unsigned __int64 uxint_t;
92 // Neither
93 #else
95 // Non-existence
96 #define BOOST_HAS_XINT 0
98 // Dummy extents
99 #define BOOST_XINT_MAX LONG_MAX
100 #define BOOST_XINT_MIN LONG_MIN
101 #define BOOST_UXINT_MAX ULONG_MAX
103 // Dummy types
104 typedef signed long xint_t;
105 typedef unsigned long uxint_t;
107 #endif // defined(BOOST_HAS_LONG_LONG)/defined(BOOST_HAS_MS_INT64)/else
109 /** \def BOOST_HAS_XINT
111 \brief Flag for extended integer types.
113 Indicates the presence of one of the two common extended integer type
114 families, either (<code>unsigned</code>) <code>long long</code> or
115 (<code>unsigned</code>) <code>__int64</code>. \c BOOST_HAS_XINT is \c 1 if
116 either type family is defined, and \c 0 if neither is.
119 /** \def BOOST_XINT_MAX
121 \brief Maximum value for the signed extended integer type.
123 \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
125 Macro constant representing the largest value the signed extended integer
126 type supports. Its composition may be another macro, an expression, or a
127 literal. Defaulted to \c LONG_MAX if \c BOOST_HAS_XINT is zero.
129 /** \def BOOST_XINT_MIN
131 \brief Minimum value for the signed extended integer type.
133 \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
135 Macro constant representing the smallest value the signed extended integer
136 type supports. Its composition may be another macro, an expression, or a
137 literal. Defaulted to \c LONG_MIN if \c BOOST_HAS_XINT is zero.
139 /** \def BOOST_UXINT_MAX
141 \brief Maximum value for the unsigned extended integer type.
143 \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
145 Macro constant representing the largest value the unsigned extended integer
146 type supports. Its composition may be another macro, an expression, or a
147 literal. Defaulted to \c ULONG_MAX if \c BOOST_HAS_XINT is zero. (Use
148 \c 0u for the type's minimum value.)
151 /** \typedef signed long boost::detail::xint_t
153 \brief Alias for the signed extended integer type.
155 \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
157 Alias representing the signed extended integer type, no matter which type
158 family it came from. Defaulted to <code>signed long</code> if
159 \c BOOST_HAS_XINT is zero.
161 /** \typedef unsigned long ::boost::detail::uxint_t
163 \brief Alias for the signed extended integer type.
165 \pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
167 Alias representing the unsigned extended integer type, no matter which type
168 family it came from. Defaulted to <code>unsigned long</code> if
169 \c BOOST_HAS_XINT is zero.
173 } // namespace detail
174 } // namespace boost
177 #endif // BOOST_DETAIL_EXTENDED_INTEGER_HPP