VLink  2.0.0
A high-performance communication middleware
vlink::Uint128 Class Referencefinal

128-bit unsigned integer represented 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. More...
 
template<typename T >
constexpr Uint128 (T v) noexcept
 Constructs from an integral-like type T (implicit on purpose). More...
 
 Uint128 (uint64_t high, uint64_t low) noexcept
 Constructs from explicit high and low halves. More...
 
Uint128 operator+ (const Uint128 &other) const noexcept
 Returns the sum of *this and other. More...
 
Uint128 operator- (const Uint128 &other) const noexcept
 Returns the difference of *this and other. More...
 
Uint128 operator* (const Uint128 &other) const noexcept
 Returns the product of *this and other. More...
 
Uint128 operator/ (const Uint128 &other) const
 Returns the quotient of *this divided by other. More...
 
Uint128 operator% (const Uint128 &other) const
 Returns the remainder of *this divided by other. More...
 
Uint128operator+= (const Uint128 &other) noexcept
 Adds other to *this in-place with carry propagation. More...
 
Uint128operator-= (const Uint128 &other) noexcept
 Subtracts other from *this in-place with borrow propagation. More...
 
Uint128operator*= (const Uint128 &other) noexcept
 Multiplies *this by other in-place. More...
 
Uint128operator/= (const Uint128 &other)
 Divides *this by other in-place. More...
 
Uint128operator%= (const Uint128 &other)
 Computes *this modulo other in-place. More...
 
Uint128 operator| (const Uint128 &other) const noexcept
 Returns the bitwise OR of *this and other. More...
 
Uint128 operator& (const Uint128 &other) const noexcept
 Returns the bitwise AND of *this and other. More...
 
Uint128 operator^ (const Uint128 &other) const noexcept
 Returns the bitwise XOR of *this and other. More...
 
Uint128 operator~ () const noexcept
 Returns the bitwise complement of *this. More...
 
Uint128 operator<< (int shift) const noexcept
 Returns *this shifted left by shift bits. More...
 
Uint128 operator>> (int shift) const noexcept
 Returns *this shifted right by shift bits (logical, zero-fill). More...
 
Uint128operator|= (const Uint128 &other) noexcept
 Applies bitwise OR with other in-place. More...
 
Uint128operator&= (const Uint128 &other) noexcept
 Applies bitwise AND with other in-place. More...
 
Uint128operator^= (const Uint128 &other) noexcept
 Applies bitwise XOR with other in-place. More...
 
Uint128operator<<= (int shift) noexcept
 Shifts *this left by shift bits in-place. More...
 
Uint128operator>>= (int shift) noexcept
 Shifts *this right by shift bits in-place (logical, zero-fill). More...
 
bool operator== (const Uint128 &other) const noexcept
 Returns true when both halves of *this and other are equal. More...
 
bool operator!= (const Uint128 &other) const noexcept
 Returns true when any half differs. More...
 
bool operator< (const Uint128 &other) const noexcept
 Returns true when *this is strictly less than other. More...
 
bool operator> (const Uint128 &other) const noexcept
 Returns true when *this is strictly greater than other. More...
 
bool operator<= (const Uint128 &other) const noexcept
 Returns true when *this is less than or equal to other. More...
 
bool operator>= (const Uint128 &other) const noexcept
 Returns true when *this is greater than or equal to other. More...
 
Uint128operator++ () noexcept
 Pre-increment with carry across the 64-bit boundary. More...
 
Uint128 operator++ (int) noexcept
 Post-increment returning a copy of the value prior to incrementing. More...
 
Uint128operator-- () noexcept
 Pre-decrement with borrow across the 64-bit boundary. More...
 
Uint128 operator-- (int) noexcept
 Post-decrement returning a copy of the value prior to decrementing. More...
 
uint64_t get_high () const noexcept
 Returns the upper 64 bits of the stored value. More...
 
uint64_t get_low () const noexcept
 Returns the lower 64 bits of the stored value. More...
 

Friends

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

Detailed Description

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

Logical layout is (high_ << 64) | low_. All arithmetic propagates carry and borrow across the 64-bit boundary so the observable behaviour matches a true 128-bit unsigned integer.

Constructor & Destructor Documentation

◆ Uint128() [1/3]

vlink::Uint128::Uint128 ( )
defaultnoexcept

Default-constructs a zero-valued Uint128.

Here is the caller graph for this function:

◆ Uint128() [2/3]

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

Constructs from an integral-like type T (implicit on purpose).

  • When T is __uint128_t (where available) the source is split into halves.
  • When T is signed the source is sign-extended: a negative value yields high_ = ~uint64_t{0} and low_ = the two's-complement bit pattern.
  • When T is unsigned the source is zero-extended into low_ with high_ = 0.
  • For any other T both halves keep their default value of 0; no diagnostic is emitted because integrality is intentionally not asserted here.
Template Parameters
TSource type (integral or __uint128_t).
Parameters
vSource value.
Note
Non-explicit by design so integral literals interoperate naturally.

◆ Uint128() [3/3]

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

Constructs from explicit high and low halves.

Details.

Parameters
highUpper 64 bits.
lowLower 64 bits.

Member Function Documentation

◆ get_high()

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

Returns the upper 64 bits of the stored value.

Returns
High half.

◆ get_low()

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

Returns the lower 64 bits of the stored value.

Returns
Low half.

◆ operator!=()

bool vlink::Uint128::operator!= ( const Uint128 other) const
inlinenoexcept

Returns true when any half differs.

Parameters
otherRight operand.
Returns
Inequality result.

◆ operator%()

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

Returns the remainder of *this divided by other.

Parameters
otherDivisor.
Returns
Remainder.
Exceptions
std::domain_errorwhen other is zero.

◆ operator%=()

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

Computes *this modulo other in-place.

Parameters
otherDivisor.
Returns
Reference to *this.
Exceptions
std::domain_errorwhen other is zero.

◆ operator&()

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

Returns the bitwise AND of *this and other.

Parameters
otherRight operand.
Returns
New value with each bit set only when set in both operands.

◆ operator&=()

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

Applies bitwise AND with other in-place.

Parameters
otherRight operand.
Returns
Reference to *this.

◆ operator*()

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

Returns the product of *this and other.

Delegates to native __uint128_t multiplication when available; otherwise falls back to mul_u128_fallback.

Parameters
otherRight operand.
Returns
Low 128 bits of the true product.

◆ operator*=()

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

Multiplies *this by other in-place.

Parameters
otherRight operand.
Returns
Reference to *this.

◆ operator+()

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

Returns the sum of *this and other.

Parameters
otherRight operand.
Returns
New value equal to *this + other (wraps on overflow).

◆ operator++() [1/2]

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

Pre-increment with carry across the 64-bit boundary.

Returns
Reference to the incremented value.

◆ operator++() [2/2]

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

Post-increment returning a copy of the value prior to incrementing.

Returns
Pre-increment value.

◆ operator+=()

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

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

Parameters
otherRight operand.
Returns
Reference to *this.

◆ operator-()

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

Returns the difference of *this and other.

Parameters
otherRight operand.
Returns
New value equal to *this - other (wraps on underflow).

◆ operator--() [1/2]

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

Pre-decrement with borrow across the 64-bit boundary.

Returns
Reference to the decremented value.

◆ operator--() [2/2]

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

Post-decrement returning a copy of the value prior to decrementing.

Returns
Pre-decrement value.

◆ operator-=()

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

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

Parameters
otherRight operand.
Returns
Reference to *this.

◆ operator/()

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

Returns the quotient of *this divided by other.

Parameters
otherDivisor.
Returns
Quotient.
Exceptions
std::domain_errorwhen other is zero.

◆ operator/=()

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

Divides *this by other in-place.

Parameters
otherDivisor.
Returns
Reference to *this.
Exceptions
std::domain_errorwhen other is zero.

◆ operator<()

bool vlink::Uint128::operator< ( const Uint128 other) const
inlinenoexcept

Returns true when *this is strictly less than other.

Compares the high half first; ties are broken by the low half.

Parameters
otherRight operand.
Returns
Comparison result.

◆ operator<<()

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

Returns *this shifted left by shift bits.

Shift values <= 0 leave the value unchanged; >= 128 produce zero; values in [64, 127] move bits across the 64-bit boundary.

Parameters
shiftBit positions to shift.
Returns
Shifted value.

◆ operator<<=()

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

Shifts *this left by shift bits in-place.

Parameters
shiftBit positions to shift.
Returns
Reference to *this.

◆ operator<=()

bool vlink::Uint128::operator<= ( const Uint128 other) const
inlinenoexcept

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

Parameters
otherRight operand.
Returns
Comparison result.

◆ operator==()

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

Returns true when both halves of *this and other are equal.

Parameters
otherRight operand.
Returns
Equality result.

◆ operator>()

bool vlink::Uint128::operator> ( const Uint128 other) const
inlinenoexcept

Returns true when *this is strictly greater than other.

Parameters
otherRight operand.
Returns
Comparison result.

◆ operator>=()

bool vlink::Uint128::operator>= ( const Uint128 other) const
inlinenoexcept

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

Parameters
otherRight operand.
Returns
Comparison result.

◆ operator>>()

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

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

Same edge-case rules as operator<<.

Parameters
shiftBit positions to shift.
Returns
Shifted value.

◆ operator>>=()

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

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

Parameters
shiftBit positions to shift.
Returns
Reference to *this.

◆ operator^()

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

Returns the bitwise XOR of *this and other.

Parameters
otherRight operand.
Returns
New value with each bit set when the bits differ between operands.

◆ operator^=()

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

Applies bitwise XOR with other in-place.

Parameters
otherRight operand.
Returns
Reference to *this.

◆ operator|()

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

Returns the bitwise OR of *this and other.

Parameters
otherRight operand.
Returns
New value with each bit set if it is set in either operand.

◆ operator|=()

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

Applies bitwise OR with other in-place.

Parameters
otherRight operand.
Returns
Reference to *this.

◆ operator~()

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

Returns the bitwise complement of *this.

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

Friends And Related Function Documentation

◆ operator<<

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

Writes the uppercase hexadecimal representation of value to os.

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

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