Fixed-Length Integers

Fixed-length integers (created by using the fixedlength parameter of the integer_t template with a non-zero value) always use the same amount of memory. They can be noticeably faster than unlimited-length integers, especially when combined with an allocator designed for their allocation pattern. However, they can be less memory-efficient for holding smaller values. They also silently discard the upper bits on any value that is too big for them, which can bite the unwary.

Note:
The number of bits refers only to the unsigned magnitude of the number. The sign is stored separately. This means that, for example, a integer_t<8> has a range of -255 to +255, not -128 to +127 like an int8_t.
Also note that when calculating with a signed fixed-length integer type, the number does not "wrap around" when it exceeds the type's size like the built-in signed integer types do. It is truncated to the lower bits instead. For example, integer_t<8>(-255) - 1 and integer_t<8>(255) + 1 will both be zero. However, the sign (on non-zero answers) is preserved, so integer_t<8>(-255) - 2 will be -1.
When used with the negative_modulus option, the number will wrap around like the built-in unsigned types.

© Copyright Chad Nelson, 2010-2011. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)