Two’s Complement Integers

Header aarith/integer/integers.hpp

The template classes integer and uinteger represent signed and unsigned integers of arbitrary, but compile-time static, precision stored in two’s complement format

The aarith integers exhibit the usual overflow/underflow behavior (i.e. modulo 2^n) which is not undefined behavior!

template<size_t Width, class WordType = uint64_t>
class aarith::uinteger : public aarith::word_array<Width, WordType>

Public Functions

inline bool constexpr is_negative() const

Returns whether the number is negative.

Returns

Always returns false

inline explicit constexpr operator uint8_t() const

Converts to an uint8_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An uint8_t storing the value of this uinteger

inline explicit constexpr operator uint16_t() const

Converts to an uint16_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An uint16_t storing the value of this uinteger

inline explicit constexpr operator uint32_t() const

Converts to an uint32_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An uint32_t storing the value of this uinteger

inline explicit constexpr operator uint64_t() const

Converts to an uint64_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An uint64_t storing the value of this uinteger

template<size_t Width, class WordType = uint64_t>
class aarith::integer : public aarith::word_array<Width, WordType>

Public Functions

inline explicit constexpr operator int8_t() const

Converts to an int8_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An int8_t storing the value of this integer

inline explicit constexpr operator int16_t() const

Converts to an int16_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An int16_t storing the value of this integer

inline explicit constexpr operator int32_t() const

Converts to an int32_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An int32_t storing the value of this integer

inline explicit constexpr operator int64_t() const

Converts to an int64_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An int64_t storing the value of this integer

inline explicit constexpr operator uint8_t() const

Converts to an uint8_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An uint8_t storing the value of this integer

inline explicit constexpr operator uint16_t() const

Converts to an uint16_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An uint16_t storing the value of this integer

inline explicit constexpr operator uint32_t() const

Converts to an uint32_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An uint32_t storing the value of this integer

inline explicit constexpr operator uint64_t() const

Converts to an uint64_t.

Note that there will be a possible loss of precision as this method simply cuts of the “overflowing” bits.

Returns

An uint64_t storing the value of this integer

inline constexpr bool is_negative() const

Returns whether the number is negative.

Returns

Whether the number is negative

Public Static Functions

static inline constexpr integer minus_one()

Returns minus one.

Returns

minus one