Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
TBigInt< NumBits, bSigned > Class Template Reference

#include <BigInt.h>

+ Collaboration diagram for TBigInt< NumBits, bSigned >:

Public Types

typedef TBigInt< NumBits, bSignedBigInt
 

Public Member Functions

FORCEINLINE uint32GetBits ()
 
FORCEINLINE const uint32GetBits () const
 
FORCEINLINE void Zero ()
 
FORCEINLINE void Set (int64 Value)
 
 TBigInt ()
 
 TBigInt (int64 Other)
 
 TBigInt (const uint32 *InBits)
 
 TBigInt (const uint8 *InData, uint32 InNumBytes)
 
 TBigInt (const FString &Value)
 
void ShiftLeftInternal (const int32 BitCount)
 
void ShiftLeftByOneInternal ()
 
void ShiftRightInternal (const int32 BitCount)
 
void ShiftRightByOneInternal ()
 
void Add (const BigInt &Other)
 
void Subtract (const BigInt &Other)
 
bool IsNegative () const
 
int32 Sign () const
 
void Negate ()
 
int32 GetHighestNonZeroWord () const
 
void MultiplyFast (const BigInt &Factor)
 
void Multiply (const BigInt &Factor)
 
void DivideWithRemainder (const BigInt &Divisor, BigInt &Remainder)
 
void Divide (const BigInt &Divisor)
 
void Modulo (const BigInt &Modulus)
 
void Sqrt ()
 
TBigIntoperator= (int64 Other)
 
int32 GetHighestNonZeroBit () const
 
int32 GetBit (int32 BitIndex) const
 
void SetBit (int32 BitIndex, int32 Value)
 
void ShiftLeft (const int32 BitCount)
 
void ShiftRight (const int32 BitCount)
 
void BitwiseOr (const BigInt &Other)
 
void BitwiseAnd (const BigInt &Other)
 
void BitwiseNot ()
 
bool IsEqual (const BigInt &Other) const
 
bool IsLess (const BigInt &Other) const
 
bool IsLessOrEqual (const BigInt &Other) const
 
bool IsGreater (const BigInt &Other) const
 
bool IsGreaterOrEqual (const BigInt &Other) const
 
bool IsZero () const
 
bool IsGreaterThanZero () const
 
bool IsLessThanZero () const
 
bool IsFirstBitSet () const
 
bool operator[] (int32 BitIndex) const
 
BigInt operator>> (int32 Count) const
 
BigIntoperator>>= (int32 Count)
 
BigInt operator<< (int32 Count) const
 
BigIntoperator<<= (int32 Count)
 
BigInt operator+ (const BigInt &Other) const
 
BigIntoperator++ ()
 
BigIntoperator+= (const BigInt &Other)
 
BigInt operator- (const BigInt &Other) const
 
BigIntoperator-- ()
 
BigIntoperator-= (const BigInt &Other)
 
BigInt operator* (const BigInt &Other) const
 
BigIntoperator*= (const BigInt &Other)
 
BigInt operator/ (const BigInt &Divider) const
 
BigIntoperator/= (const BigInt &Divider)
 
BigInt operator% (const BigInt &Modulus) const
 
BigIntoperator%= (const BigInt &Modulus)
 
bool operator< (const BigInt &Other) const
 
bool operator<= (const BigInt &Other) const
 
bool operator> (const BigInt &Other) const
 
bool operator>= (const BigInt &Other) const
 
bool operator== (const BigInt &Other) const
 
bool operator!= (const BigInt &Other) const
 
BigInt operator& (const BigInt &Other) const
 
BigIntoperator&= (const BigInt &Other)
 
BigInt operator| (const BigInt &Other) const
 
BigIntoperator|= (const BigInt &Other)
 
BigInt operator~ () const
 
int64 ToInt () const
 
FString ToString () const
 
void Parse (const FString &Value)
 

Static Public Attributes

static BigInt One
 

Private Types

enum  { BitsPerWord = 32 , NumWords = NumBits / BitsPerWord }
 

Static Private Member Functions

static FORCEINLINE void MakePositiveFactors (BigInt &FactorA, int32 &SignA, BigInt &FactorB, int32 &SignB)
 
static FORCEINLINE void RestoreSign (BigInt &Result, int32 SignA, int32 SignB)
 

Private Attributes

uint32 Bits [NumWords]
 

Friends

FArchiveoperator<< (FArchive &Ar, BigInt &Value)
 

Detailed Description

template<int32 NumBits, bool bSigned = true>
class TBigInt< NumBits, bSigned >

n-bit integer.

Todo
: optimize Data is stored as an array of 32-bit words from the least to the most significant Doesn't handle overflows (not a big issue, we can always use a bigger bit count) Minimum sanity checks. Can convert from int64 and back (by truncating the result, this is mostly for testing)

Definition at line 18 of file BigInt.h.

Member Typedef Documentation

◆ BigInt

template<int32 NumBits, bool bSigned = true>
typedef TBigInt<NumBits, bSigned> TBigInt< NumBits, bSigned >::BigInt

Definition at line 22 of file BigInt.h.

Member Enumeration Documentation

◆ anonymous enum

template<int32 NumBits, bool bSigned = true>
anonymous enum
private
Enumerator
BitsPerWord 

Word size.

NumWords 

Definition at line 28 of file BigInt.h.

Constructor & Destructor Documentation

◆ TBigInt() [1/5]

template<int32 NumBits, bool bSigned = true>
TBigInt< NumBits, bSigned >::TBigInt ( )
inline

Default constructor. Initializes the number to zero.

Definition at line 111 of file BigInt.h.

◆ TBigInt() [2/5]

template<int32 NumBits, bool bSigned = true>
TBigInt< NumBits, bSigned >::TBigInt ( int64 Other)
inline

Constructor. Initializes this big int with a 64 bit integer value.

Parameters
OtherThe value to set.

Definition at line 121 of file BigInt.h.

◆ TBigInt() [3/5]

template<int32 NumBits, bool bSigned = true>
TBigInt< NumBits, bSigned >::TBigInt ( const uint32 * InBits)
inlineexplicit

Constructor. Initializes this big int with an array of words.

Definition at line 129 of file BigInt.h.

◆ TBigInt() [4/5]

template<int32 NumBits, bool bSigned = true>
TBigInt< NumBits, bSigned >::TBigInt ( const uint8 * InData,
uint32 InNumBytes )
inlineexplicit

Constructor. Initializes this big int with an array of bytes.

Definition at line 137 of file BigInt.h.

◆ TBigInt() [5/5]

template<int32 NumBits, bool bSigned = true>
TBigInt< NumBits, bSigned >::TBigInt ( const FString & Value)
inlineexplicit

Constructor. Initializes this big int with a string representing a hex value.

Definition at line 152 of file BigInt.h.

Member Function Documentation

◆ Add()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::Add ( const BigInt & Other)
inline

Adds two integers.

Definition at line 260 of file BigInt.h.

◆ BitwiseAnd()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::BitwiseAnd ( const BigInt & Other)
inline

Bitwise 'and'

Definition at line 634 of file BigInt.h.

◆ BitwiseNot()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::BitwiseNot ( )
inline

Bitwise 'not'

Definition at line 645 of file BigInt.h.

◆ BitwiseOr()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::BitwiseOr ( const BigInt & Other)
inline

Bitwise 'or'

Definition at line 623 of file BigInt.h.

◆ Divide()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::Divide ( const BigInt & Divisor)
inline

Divides two integers.

Definition at line 457 of file BigInt.h.

◆ DivideWithRemainder()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::DivideWithRemainder ( const BigInt & Divisor,
BigInt & Remainder )
inline

Divides two integers with remainder.

Definition at line 382 of file BigInt.h.

◆ GetBit()

template<int32 NumBits, bool bSigned = true>
int32 TBigInt< NumBits, bSigned >::GetBit ( int32 BitIndex) const
inline

Returns a bit value as an integer value (0 or 1).

Definition at line 546 of file BigInt.h.

◆ GetBits() [1/2]

template<int32 NumBits, bool bSigned = true>
FORCEINLINE uint32 * TBigInt< NumBits, bSigned >::GetBits ( )
inline

Definition at line 82 of file BigInt.h.

◆ GetBits() [2/2]

template<int32 NumBits, bool bSigned = true>
FORCEINLINE const uint32 * TBigInt< NumBits, bSigned >::GetBits ( ) const
inline

Definition at line 87 of file BigInt.h.

◆ GetHighestNonZeroBit()

template<int32 NumBits, bool bSigned = true>
int32 TBigInt< NumBits, bSigned >::GetHighestNonZeroBit ( ) const
inline

Returns the index of the highest non-zero bit. -1 if no such bit exists.

Definition at line 529 of file BigInt.h.

◆ GetHighestNonZeroWord()

template<int32 NumBits, bool bSigned = true>
int32 TBigInt< NumBits, bSigned >::GetHighestNonZeroWord ( ) const
inline

Returns the index of the highest word that is not zero. -1 if no such word exists.

Definition at line 320 of file BigInt.h.

◆ IsEqual()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsEqual ( const BigInt & Other) const
inline

Checks if two integers are equal.

Definition at line 656 of file BigInt.h.

◆ IsFirstBitSet()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsFirstBitSet ( ) const
inline

Definition at line 779 of file BigInt.h.

◆ IsGreater()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsGreater ( const BigInt & Other) const
inline

this > Other

Definition at line 714 of file BigInt.h.

◆ IsGreaterOrEqual()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsGreaterOrEqual ( const BigInt & Other) const
inline

this >= Other

Definition at line 735 of file BigInt.h.

◆ IsGreaterThanZero()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsGreaterThanZero ( ) const
inline

this > 0

Definition at line 766 of file BigInt.h.

◆ IsLess()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsLess ( const BigInt & Other) const
inline

this < Other

Definition at line 672 of file BigInt.h.

◆ IsLessOrEqual()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsLessOrEqual ( const BigInt & Other) const
inline

this <= Other

Definition at line 693 of file BigInt.h.

◆ IsLessThanZero()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsLessThanZero ( ) const
inline

this < 0

Definition at line 774 of file BigInt.h.

◆ IsNegative()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsNegative ( ) const
inline

Checks if this integer is negative.

Definition at line 285 of file BigInt.h.

◆ IsZero()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::IsZero ( ) const
inline

this == 0

Definition at line 756 of file BigInt.h.

◆ MakePositiveFactors()

template<int32 NumBits, bool bSigned = true>
static FORCEINLINE void TBigInt< NumBits, bSigned >::MakePositiveFactors ( BigInt & FactorA,
int32 & SignA,
BigInt & FactorB,
int32 & SignB )
inlinestaticprivate

Makes sure both factors are positive integers and stores their original signs

Parameters
FactorAfirst factor
SignAsign of the first factor
FactorBsecond factor
SignBsign of the second pactor

Definition at line 48 of file BigInt.h.

◆ Modulo()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::Modulo ( const BigInt & Modulus)
inline

Performs modulo operation on this integer.

Definition at line 466 of file BigInt.h.

◆ Multiply()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::Multiply ( const BigInt & Factor)
inline

Multiplies two integers.

Definition at line 363 of file BigInt.h.

◆ MultiplyFast()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::MultiplyFast ( const BigInt & Factor)
inline

Multiplies two positive integers.

Definition at line 330 of file BigInt.h.

◆ Negate()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::Negate ( )
inline

Negates this integer. value = -value

Definition at line 308 of file BigInt.h.

◆ operator!=()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::operator!= ( const BigInt & Other) const
inline

Definition at line 920 of file BigInt.h.

◆ operator%()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator% ( const BigInt & Modulus) const
inline

Definition at line 882 of file BigInt.h.

◆ operator%=()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator%= ( const BigInt & Modulus)
inline

Definition at line 889 of file BigInt.h.

◆ operator&()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator& ( const BigInt & Other) const
inline

Definition at line 925 of file BigInt.h.

◆ operator&=()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator&= ( const BigInt & Other)
inline

Definition at line 932 of file BigInt.h.

◆ operator*()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator* ( const BigInt & Other) const
inline

Definition at line 856 of file BigInt.h.

◆ operator*=()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator*= ( const BigInt & Other)
inline

Definition at line 863 of file BigInt.h.

◆ operator+()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator+ ( const BigInt & Other) const
inline

Definition at line 818 of file BigInt.h.

◆ operator++()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator++ ( )
inline

Definition at line 825 of file BigInt.h.

◆ operator+=()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator+= ( const BigInt & Other)
inline

Definition at line 831 of file BigInt.h.

◆ operator-()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator- ( const BigInt & Other) const
inline

Definition at line 837 of file BigInt.h.

◆ operator--()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator-- ( )
inline

Definition at line 844 of file BigInt.h.

◆ operator-=()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator-= ( const BigInt & Other)
inline

Definition at line 850 of file BigInt.h.

◆ operator/()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator/ ( const BigInt & Divider) const
inline

Definition at line 869 of file BigInt.h.

◆ operator/=()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator/= ( const BigInt & Divider)
inline

Definition at line 876 of file BigInt.h.

◆ operator<()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::operator< ( const BigInt & Other) const
inline

Definition at line 895 of file BigInt.h.

◆ operator<<()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator<< ( int32 Count) const
inline

Definition at line 805 of file BigInt.h.

◆ operator<<=()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator<<= ( int32 Count)
inline

Definition at line 812 of file BigInt.h.

◆ operator<=()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::operator<= ( const BigInt & Other) const
inline

Definition at line 900 of file BigInt.h.

◆ operator=()

template<int32 NumBits, bool bSigned = true>
TBigInt & TBigInt< NumBits, bSigned >::operator= ( int64 Other)
inline

Assignment operator for int64 values.

Definition at line 520 of file BigInt.h.

◆ operator==()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::operator== ( const BigInt & Other) const
inline

Definition at line 915 of file BigInt.h.

◆ operator>()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::operator> ( const BigInt & Other) const
inline

Definition at line 905 of file BigInt.h.

◆ operator>=()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::operator>= ( const BigInt & Other) const
inline

Definition at line 910 of file BigInt.h.

◆ operator>>()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator>> ( int32 Count) const
inline

Definition at line 792 of file BigInt.h.

◆ operator>>=()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator>>= ( int32 Count)
inline

Definition at line 799 of file BigInt.h.

◆ operator[]()

template<int32 NumBits, bool bSigned = true>
bool TBigInt< NumBits, bSigned >::operator[] ( int32 BitIndex) const
inline

Bit indexing operator

Definition at line 786 of file BigInt.h.

◆ operator|()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator| ( const BigInt & Other) const
inline

Definition at line 938 of file BigInt.h.

◆ operator|=()

template<int32 NumBits, bool bSigned = true>
BigInt & TBigInt< NumBits, bSigned >::operator|= ( const BigInt & Other)
inline

Definition at line 945 of file BigInt.h.

◆ operator~()

template<int32 NumBits, bool bSigned = true>
BigInt TBigInt< NumBits, bSigned >::operator~ ( ) const
inline

Definition at line 951 of file BigInt.h.

◆ Parse()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::Parse ( const FString & Value)
inline

Parses a string representing a hex value

Definition at line 991 of file BigInt.h.

◆ RestoreSign()

template<int32 NumBits, bool bSigned = true>
static FORCEINLINE void TBigInt< NumBits, bSigned >::RestoreSign ( BigInt & Result,
int32 SignA,
int32 SignB )
inlinestaticprivate

Restores a sign of a result based on the sign of two factors that produced the result.

Parameters
Resultmath opration result
SignAsign of the first factor
SignBsign of the second factor

Definition at line 72 of file BigInt.h.

◆ Set()

template<int32 NumBits, bool bSigned = true>
FORCEINLINE void TBigInt< NumBits, bSigned >::Set ( int64 Value)
inline

Initializes this big int with a 64 bit integer value.

Parameters
ValueThe value to set.

Definition at line 103 of file BigInt.h.

◆ SetBit()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::SetBit ( int32 BitIndex,
int32 Value )
inline

Sets a bit value.

Definition at line 556 of file BigInt.h.

◆ ShiftLeft()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::ShiftLeft ( const int32 BitCount)
inline

Shift left by the specified amount of bits.

Parameters
BitCountthe number of bits to shift.

Definition at line 575 of file BigInt.h.

◆ ShiftLeftByOneInternal()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::ShiftLeftByOneInternal ( )
inline

Shift left by 1 bit.

Definition at line 195 of file BigInt.h.

◆ ShiftLeftInternal()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::ShiftLeftInternal ( const int32 BitCount)
inline

Shift left by the specified amount of bits. Does not check if BitCount is valid.

Parameters
BitCountthe number of bits to shift.

Definition at line 162 of file BigInt.h.

◆ ShiftRight()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::ShiftRight ( const int32 BitCount)
inline

Shift right by the specified amount of bits.

Parameters
BitCountthe number of bits to shift.

Definition at line 600 of file BigInt.h.

◆ ShiftRightByOneInternal()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::ShiftRightByOneInternal ( )
inline

Shift right by 1 bit.

Definition at line 245 of file BigInt.h.

◆ ShiftRightInternal()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::ShiftRightInternal ( const int32 BitCount)
inline

Shift right by the specified amount of bits. Does not check if BitCount is valid.

Parameters
BitCountthe number of bits to shift.

Definition at line 212 of file BigInt.h.

◆ Sign()

template<int32 NumBits, bool bSigned = true>
int32 TBigInt< NumBits, bSigned >::Sign ( ) const
inline

Returns the sign of this integer.

Definition at line 300 of file BigInt.h.

◆ Sqrt()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::Sqrt ( )
inline

Calculates square root of this integer.

Definition at line 485 of file BigInt.h.

◆ Subtract()

template<int32 NumBits, bool bSigned = true>
void TBigInt< NumBits, bSigned >::Subtract ( const BigInt & Other)
inline

Subtracts two integers.

Definition at line 275 of file BigInt.h.

◆ ToInt()

template<int32 NumBits, bool bSigned = true>
int64 TBigInt< NumBits, bSigned >::ToInt ( ) const
inline

Returns the value of this big int as a 64-bit integer. If the value is greater, the higher bits are truncated.

Definition at line 962 of file BigInt.h.

◆ ToString()

template<int32 NumBits, bool bSigned = true>
FString TBigInt< NumBits, bSigned >::ToString ( ) const
inline

Returns this big int as a string.

Definition at line 970 of file BigInt.h.

◆ Zero()

template<int32 NumBits, bool bSigned = true>
FORCEINLINE void TBigInt< NumBits, bSigned >::Zero ( )
inline

Sets this integer to 0.

Definition at line 93 of file BigInt.h.

Friends And Related Symbol Documentation

◆ operator<<

template<int32 NumBits, bool bSigned = true>
FArchive & operator<< ( FArchive & Ar,
BigInt & Value )
friend

Serialization.

Definition at line 1015 of file BigInt.h.

Member Data Documentation

◆ Bits

template<int32 NumBits, bool bSigned = true>
uint32 TBigInt< NumBits, bSigned >::Bits[NumWords]
private

All bits stored as an array of words.

Definition at line 38 of file BigInt.h.

◆ One

template<int32 NumBits, bool bSigned>
TBigInt< NumBits, bSigned > TBigInt< NumBits, bSigned >::One
static

Definition at line 24 of file BigInt.h.


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