VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::Uint128 Class Referencefinal

128-bit unsigned integer stored as two 64-bit halves with full operator support. More...

#include <uint128.h>

Collaboration diagram for vlink::Uint128:

Public Member Functions

 Uint128 () noexcept=default
 Default-constructs a zero-valued Uint128.
template<typename T>
constexpr Uint128 (T v) noexcept
 Constructs a Uint128 from any integral type T (implicit conversion).
 Uint128 (uint64_t high, uint64_t low) noexcept
 Constructs a Uint128 from explicit high and low 64-bit halves.
Uint128 operator+ (const Uint128 &other) const noexcept
 Returns the sum of *this and other.
Uint128 operator- (const Uint128 &other) const noexcept
 Returns the difference of *this and other.
Uint128 operator* (const Uint128 &other) const noexcept
 Returns the product of *this and other.
Uint128 operator/ (const Uint128 &other) const
 Returns the quotient of *this divided by other.
Uint128 operator% (const Uint128 &other) const
 Returns the remainder of *this divided by other.
Uint128operator+= (const Uint128 &other) noexcept
 Adds other to *this in-place with carry propagation.
Uint128operator-= (const Uint128 &other) noexcept
 Subtracts other from *this in-place with borrow propagation.
Uint128operator*= (const Uint128 &other) noexcept
 Multiplies *this by other in-place.
Uint128operator/= (const Uint128 &other)
 Divides *this by other in-place.
Uint128operator%= (const Uint128 &other)
 Computes *this modulo other in-place.
Uint128 operator| (const Uint128 &other) const noexcept
 Returns the bitwise OR of *this and other.
Uint128 operator& (const Uint128 &other) const noexcept
 Returns the bitwise AND of *this and other.
Uint128 operator^ (const Uint128 &other) const noexcept
 Returns the bitwise XOR of *this and other.
Uint128 operator~ () const noexcept
 Returns the bitwise NOT (complement) of *this.
Uint128 operator<< (int shift) const noexcept
 Returns *this shifted left by shift bits.
Uint128 operator>> (int shift) const noexcept
 Returns *this shifted right by shift bits (logical, zero-fill).
Uint128operator|= (const Uint128 &other) noexcept
 Applies bitwise OR with other in-place.
Uint128operator&= (const Uint128 &other) noexcept
 Applies bitwise AND with other in-place.
Uint128operator^= (const Uint128 &other) noexcept
 Applies bitwise XOR with other in-place.
Uint128operator<<= (int shift) noexcept
 Shifts *this left by shift bits in-place.
Uint128operator>>= (int shift) noexcept
 Shifts *this right by shift bits in-place (logical, zero-fill).
bool operator== (const Uint128 &other) const noexcept
 Returns true if *this equals other.
bool operator!= (const Uint128 &other) const noexcept
 Returns true if *this does not equal other.
bool operator< (const Uint128 &other) const noexcept
 Returns true if *this is less than other.
bool operator> (const Uint128 &other) const noexcept
 Returns true if *this is greater than other.
bool operator<= (const Uint128 &other) const noexcept
 Returns true if *this is less than or equal to other.
bool operator>= (const Uint128 &other) const noexcept
 Returns true if *this is greater than or equal to other.
Uint128operator++ () noexcept
 Pre-increment: increments the value by one and returns *this.
Uint128 operator++ (int) noexcept
 Post-increment: increments the value by one and returns the previous value.
Uint128operator-- () noexcept
 Pre-decrement: decrements the value by one and returns *this.
Uint128 operator-- (int) noexcept
 Post-decrement: decrements the value by one and returns the previous value.
uint64_t get_high () const noexcept
 Returns the upper 64 bits of the 128-bit value.
uint64_t get_low () const noexcept
 Returns the lower 64 bits of the 128-bit value.

Friends

VLINK_EXPORT friend std::ostream & operator<< (std::ostream &os, const Uint128 &value) noexcept
 Writes the hexadecimal string representation of the value to os.

Detailed Description

128-bit unsigned integer stored as two 64-bit halves with full operator support.

Stores the value as (high_ << 64) | low_. All arithmetic correctly handles carry/borrow across the 64-bit boundary. Division and modulo are implemented using a portable binary-long-division algorithm (u128_divmod).

Constructor & Destructor Documentation

◆ Uint128() [1/3]

vlink::Uint128::Uint128 ( )
defaultnoexcept

Default-constructs a zero-valued Uint128.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Uint128() [2/3]

template<typename T>
vlink::Uint128::Uint128 ( T v)
inlineconstexprnoexcept

Constructs a Uint128 from any integral type T (implicit conversion).

  • If T is __uint128_t (available on GCC/Clang 64-bit), splits into high and low halves.
  • Otherwise zero-extends the value into low_; high_ is set to zero.
Template Parameters
TSource integral type.
Parameters
vSource value.
Note
This constructor is intentionally non-explicit to allow natural integral literals.

◆ Uint128() [3/3]

vlink::Uint128::Uint128 ( uint64_t high,
uint64_t low )
inlineexplicitnoexcept

Constructs a Uint128 from explicit high and low 64-bit halves.

Details.

Parameters
highUpper 64 bits.
lowLower 64 bits.

Member Function Documentation

◆ get_high()

uint64_t vlink::Uint128::get_high ( ) const
inlinenodiscardnoexcept

Returns the upper 64 bits of the 128-bit value.

Returns
High 64-bit word.
Here is the caller graph for this function:

◆ get_low()

uint64_t vlink::Uint128::get_low ( ) const
inlinenodiscardnoexcept

Returns the lower 64 bits of the 128-bit value.

Returns
Low 64-bit word.
Here is the caller graph for this function:

◆ operator!=()

bool vlink::Uint128::operator!= ( const Uint128 & other) const
inlinenodiscardnoexcept

Returns true if *this does not equal other.

Parameters
otherRight-hand operand.
Returns
true if any word differs.
Here is the call graph for this function:

◆ operator%()

Uint128 vlink::Uint128::operator% ( const Uint128 & other) const
inline

Returns the remainder of *this divided by other.

Parameters
otherDivisor.
Returns
New Uint128 equal to *this % other.
Exceptions
std::domain_error(or similar) if other is zero.
Here is the call graph for this function:

◆ operator%=()

Uint128 & vlink::Uint128::operator%= ( const Uint128 & other)
inline

Computes *this modulo other in-place.

Parameters
otherDivisor.
Returns
Reference to *this.
Exceptions
std::domain_error(or similar) if other is zero.
Here is the call graph for this function:

◆ operator&()

Uint128 vlink::Uint128::operator& ( const Uint128 & other) const
inlinenoexcept

Returns the bitwise AND of *this and other.

Parameters
otherRight-hand operand.
Returns
New Uint128 with each bit set only if set in both operands.
Here is the call graph for this function:

◆ operator&=()

Uint128 & vlink::Uint128::operator&= ( const Uint128 & other)
inlinenoexcept

Applies bitwise AND with other in-place.

Parameters
otherRight-hand operand.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator*()

Uint128 vlink::Uint128::operator* ( const Uint128 & other) const
inlinenoexcept

Returns the product of *this and other.

Uses __uint128_t multiplication when available; falls back to mul_u128_fallback otherwise.

Parameters
otherRight-hand operand.
Returns
New Uint128 equal to *this * other (low 128 bits of true product).
Here is the call graph for this function:

◆ operator*=()

Uint128 & vlink::Uint128::operator*= ( const Uint128 & other)
inlinenoexcept

Multiplies *this by other in-place.

Parameters
otherRight-hand operand.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator+()

Uint128 vlink::Uint128::operator+ ( const Uint128 & other) const
inlinenoexcept

Returns the sum of *this and other.

Parameters
otherRight-hand operand.
Returns
New Uint128 equal to *this + other.
Here is the call graph for this function:

◆ operator++() [1/2]

Uint128 & vlink::Uint128::operator++ ( )
inlinenoexcept

Pre-increment: increments the value by one and returns *this.

Carry from the low word is propagated to the high word.

Returns
Reference to the incremented value.
Here is the call graph for this function:

◆ operator++() [2/2]

Uint128 vlink::Uint128::operator++ ( int )
inlinenoexcept

Post-increment: increments the value by one and returns the previous value.

Returns
Copy of the value before incrementing.
Here is the call graph for this function:

◆ operator+=()

Uint128 & vlink::Uint128::operator+= ( const Uint128 & other)
inlinenoexcept

Adds other to *this in-place with carry propagation.

Parameters
otherRight-hand operand.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator-()

Uint128 vlink::Uint128::operator- ( const Uint128 & other) const
inlinenoexcept

Returns the difference of *this and other.

Parameters
otherRight-hand operand.
Returns
New Uint128 equal to *this - other (wraps on underflow).
Here is the call graph for this function:

◆ operator--() [1/2]

Uint128 & vlink::Uint128::operator-- ( )
inlinenoexcept

Pre-decrement: decrements the value by one and returns *this.

Borrow from the low word underflow is propagated to the high word.

Returns
Reference to the decremented value.
Here is the call graph for this function:

◆ operator--() [2/2]

Uint128 vlink::Uint128::operator-- ( int )
inlinenoexcept

Post-decrement: decrements the value by one and returns the previous value.

Returns
Copy of the value before decrementing.
Here is the call graph for this function:

◆ operator-=()

Uint128 & vlink::Uint128::operator-= ( const Uint128 & other)
inlinenoexcept

Subtracts other from *this in-place with borrow propagation.

Parameters
otherRight-hand operand.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator/()

Uint128 vlink::Uint128::operator/ ( const Uint128 & other) const
inline

Returns the quotient of *this divided by other.

Parameters
otherDivisor.
Returns
New Uint128 equal to *this / other.
Exceptions
std::domain_error(or similar) if other is zero.
Here is the call graph for this function:

◆ operator/=()

Uint128 & vlink::Uint128::operator/= ( const Uint128 & other)
inline

Divides *this by other in-place.

Parameters
otherDivisor.
Returns
Reference to *this.
Exceptions
std::domain_error(or similar) if other is zero.
Here is the call graph for this function:

◆ operator<()

bool vlink::Uint128::operator< ( const Uint128 & other) const
inlinenodiscardnoexcept

Returns true if *this is less than other.

Compares the high word first; if equal, compares the low word.

Parameters
otherRight-hand operand.
Returns
true if *this < other.
Here is the call graph for this function:

◆ operator<<()

Uint128 vlink::Uint128::operator<< ( int shift) const
inlinenoexcept

Returns *this shifted left by shift bits.

  • Shift <= 0: returns *this unchanged.
  • Shift >= 128: returns zero.
  • Shift in [64, 127]: low bits are shifted into the high word.
Parameters
shiftNumber of bit positions to shift left.
Returns
Shifted value.
Here is the call graph for this function:

◆ operator<<=()

Uint128 & vlink::Uint128::operator<<= ( int shift)
inlinenoexcept

Shifts *this left by shift bits in-place.

Parameters
shiftNumber of bit positions to shift left.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator<=()

bool vlink::Uint128::operator<= ( const Uint128 & other) const
inlinenodiscardnoexcept

Returns true if *this is less than or equal to other.

Parameters
otherRight-hand operand.
Returns
true if *this <= other.
Here is the call graph for this function:

◆ operator==()

bool vlink::Uint128::operator== ( const Uint128 & other) const
inlinenodiscardnoexcept

Returns true if *this equals other.

Parameters
otherRight-hand operand.
Returns
true if high and low words are both equal.
Here is the call graph for this function:

◆ operator>()

bool vlink::Uint128::operator> ( const Uint128 & other) const
inlinenodiscardnoexcept

Returns true if *this is greater than other.

Parameters
otherRight-hand operand.
Returns
true if *this > other.
Here is the call graph for this function:

◆ operator>=()

bool vlink::Uint128::operator>= ( const Uint128 & other) const
inlinenodiscardnoexcept

Returns true if *this is greater than or equal to other.

Parameters
otherRight-hand operand.
Returns
true if *this >= other.
Here is the call graph for this function:

◆ operator>>()

Uint128 vlink::Uint128::operator>> ( int shift) const
inlinenoexcept

Returns *this shifted right by shift bits (logical, zero-fill).

  • Shift <= 0: returns *this unchanged.
  • Shift >= 128: returns zero.
  • Shift in [64, 127]: high bits are shifted into the low word.
Parameters
shiftNumber of bit positions to shift right.
Returns
Shifted value.
Here is the call graph for this function:

◆ operator>>=()

Uint128 & vlink::Uint128::operator>>= ( int shift)
inlinenoexcept

Shifts *this right by shift bits in-place (logical, zero-fill).

Parameters
shiftNumber of bit positions to shift right.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator^()

Uint128 vlink::Uint128::operator^ ( const Uint128 & other) const
inlinenoexcept

Returns the bitwise XOR of *this and other.

Parameters
otherRight-hand operand.
Returns
New Uint128 with each bit set if it differs between operands.
Here is the call graph for this function:

◆ operator^=()

Uint128 & vlink::Uint128::operator^= ( const Uint128 & other)
inlinenoexcept

Applies bitwise XOR with other in-place.

Parameters
otherRight-hand operand.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator|()

Uint128 vlink::Uint128::operator| ( const Uint128 & other) const
inlinenoexcept

Returns the bitwise OR of *this and other.

Parameters
otherRight-hand operand.
Returns
New Uint128 with each bit set if it is set in either operand.
Here is the call graph for this function:

◆ operator|=()

Uint128 & vlink::Uint128::operator|= ( const Uint128 & other)
inlinenoexcept

Applies bitwise OR with other in-place.

Parameters
otherRight-hand operand.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator~()

Uint128 vlink::Uint128::operator~ ( ) const
inlinenoexcept

Returns the bitwise NOT (complement) of *this.

Returns
New Uint128 with all 128 bits inverted.
Here is the call graph for this function:

◆ operator<<

VLINK_EXPORT friend std::ostream & operator<< ( std::ostream & os,
const Uint128 & value )
friend

Writes the hexadecimal string representation of the value to os.

Parameters
osOutput stream.
valueValue to print.
Returns
Reference to os.

The documentation for this class was generated from the following file: