Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cUInt64 Class Reference

#include <cUInt64.h>

Public Types

typedef UINT64 UNIT_t
 

Public Member Functions

 cUInt64 ()
 
 cUInt64 (UNIT_t n)
 
 cUInt64 (const char *pszVal, RADIX_t n=10)
 
bool isZero () const
 
bool isOdd () const
 
bool IsSet (BIT_ENUM_t nBit) const
 
bool operator== (const cUInt64 &n) const
 
bool operator!= (const cUInt64 &n) const
 
bool operator== (UNIT_t n) const
 
bool operator> (const cUInt64 &n) const
 
bool operator< (const cUInt64 &n) const
 
bool operator<= (const cUInt64 &n) const
 
template<typename TYPE >
TYPE get_Val () const
 
void operator++ ()
 
void operator++ (int)
 
void operator-- ()
 
void operator-- (int)
 
cUInt64operator+= (const cUInt64 &n)
 
cUInt64operator-= (const cUInt64 &n)
 
cUInt64operator*= (const cUInt64 &x)
 
cUInt64 operator* (const cUInt64 &x) const
 
void operator%= (const cUInt64 &x)
 
void SetBit (BIT_ENUM_t uiBit)
 
cUInt64operator|= (const cUInt64 &n)
 
cUInt64operator&= (const cUInt64 &n)
 
cUInt64operator^= (const cUInt64 &n)
 
cUInt64operator<<= (BIT_ENUM_t uiBits)
 
cUInt64operator>>= (BIT_ENUM_t uiBits)
 
StrLen_t GetStr (char *pszOut, StrLen_t iOutMax, RADIX_t nBaseRadix=10) const
 
cString GetStr (RADIX_t nBaseRadix=10) const
 
bool SetStr (const char *pszVal, RADIX_t nBaseRadix=10, const char **ppszEnd=(const char **) nullptr)
 
BIT_ENUM_t get_Highest1Bit () const
 
HRESULT SetRandomBits (BIT_ENUM_t nBits)
 
void SetPowerMod (const cUInt64 &base, const cUInt64 &exponent, const cUInt64 &modulus)
 
bool isPrime () const
 
int SetRandomPrime (BIT_ENUM_t nBits, cThreadState *pCancel=nullptr)
 
void OpBitShiftLeft1 (UNIT_t nBitMask)
 

Static Public Member Functions

static void __stdcall Divide (const cUInt64 &dividend, const cUInt64 &divisor, OUT cUInt64 &quotient, OUT cUInt64 &remainder)
 
static void __stdcall EuclideanAlgorithm (const cUInt64 &x, const cUInt64 &y, OUT cUInt64 &a, OUT cUInt64 &b, OUT cUInt64 &g)
 

Static Public Attributes

static const unsigned k_UNIT_BITS = 64
 

Friends

class cUInt64Tests
 

Detailed Description

emulate 64 bit unsigned integer as a native type for systems that don't actually support this. QWord if ! USE_INT64 then ASSUME we DONT support 64 bit int types natively. Assume all platforms support 32 bit types. we don't support __int64 (_MSC_VER) or int64_t (C99/GCC standard) native. like cUnion64 or LARGE_INTEGER as a native type for operators. same size as UINT64 use typedef cUInt64 UINT64; if ! USE_INT64

Member Typedef Documentation

◆ UNIT_t

typedef UINT64 Gray::cUInt64::UNIT_t

Constructor & Destructor Documentation

◆ cUInt64() [1/3]

Gray::cUInt64::cUInt64 ( )
inline

◆ cUInt64() [2/3]

Gray::cUInt64::cUInt64 ( UNIT_t  n)
inline

◆ cUInt64() [3/3]

Gray::cUInt64::cUInt64 ( const char *  pszVal,
RADIX_t  n = 10 
)
inline

Member Function Documentation

◆ Divide()

void GRAYCALL Gray::cUInt64::Divide ( const cUInt64 dividend,
const cUInt64 divisor,
OUT cUInt64 quotient,
OUT cUInt64 remainder 
)
static

Division with remainder get quotient,remainder for dividend/divisor.

◆ EuclideanAlgorithm()

void GRAYCALL Gray::cUInt64::EuclideanAlgorithm ( const cUInt64 x,
const cUInt64 y,
OUT cUInt64 a,
OUT cUInt64 b,
OUT cUInt64 g 
)
static

This function uses the Euclidean algorithm to find the greatest common divisor g of the positive integers x and y and also two integers a and b such that ax - by = g, 1 <= a <= y and 0 <= b < x.

This function will fail in undefined ways if either x or y is zero.

◆ get_Highest1Bit()

BIT_ENUM_t Gray::cUInt64::get_Highest1Bit ( ) const

◆ get_Val()

template<typename TYPE >
TYPE Gray::cUInt64::get_Val ( ) const
inline

just default to assume TYPE is unsigned.

◆ GetStr() [1/2]

StrLen_t Gray::cUInt64::GetStr ( char *  pszOut,
StrLen_t  iOutMax,
RADIX_t  nBaseRadix = 10 
) const

◆ GetStr() [2/2]

cString Gray::cUInt64::GetStr ( RADIX_t  nBaseRadix = 10) const

encode value as string.

Note
We can estimate the max string size via get_Highest1Bit()

◆ isOdd()

bool Gray::cUInt64::isOdd ( ) const
inline

◆ isPrime()

bool Gray::cUInt64::isPrime ( ) const

This function uses Fermat's (little) Theorem 100 times to test the primeness of a (large) positive integer. if p is prime then for any integer x, ( x^p - x ) will be evenly divisible by p. Small Primes: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 http://en.wikipedia.org/wiki/Primality_test

Note
this can be VERY slow for big numbers.

◆ IsSet()

bool Gray::cUInt64::IsSet ( BIT_ENUM_t  nBit) const
inline

Gets the state of the enumerated bit. which has value 2^nBit. Bits beyond m_nBlksUse are considered to be 0.

◆ isZero()

bool Gray::cUInt64::isZero ( ) const
inline

◆ OpBitShiftLeft1()

void Gray::cUInt64::OpBitShiftLeft1 ( UNIT_t  nBitMask)

◆ operator!=()

bool Gray::cUInt64::operator!= ( const cUInt64 n) const
inline

◆ operator%=()

void Gray::cUInt64::operator%= ( const cUInt64 x)
inline

Modulus *this by x.

◆ operator&=()

cUInt64& Gray::cUInt64::operator&= ( const cUInt64 n)
inline

◆ operator*()

cUInt64 Gray::cUInt64::operator* ( const cUInt64 x) const
inline

◆ operator*=()

cUInt64& Gray::cUInt64::operator*= ( const cUInt64 x)
inline

◆ operator++() [1/2]

void Gray::cUInt64::operator++ ( )
inline

◆ operator++() [2/2]

void Gray::cUInt64::operator++ ( int  )
inline

Post fix increment: same as prefix

◆ operator+=()

cUInt64& Gray::cUInt64::operator+= ( const cUInt64 n)
inline

◆ operator--() [1/2]

void Gray::cUInt64::operator-- ( )
inline

◆ operator--() [2/2]

void Gray::cUInt64::operator-- ( int  )
inline

Postfix decrement: same as prefix

◆ operator-=()

cUInt64& Gray::cUInt64::operator-= ( const cUInt64 n)
inline

◆ operator<()

bool Gray::cUInt64::operator< ( const cUInt64 n) const
inline

◆ operator<<=()

cUInt64& Gray::cUInt64::operator<<= ( BIT_ENUM_t  uiBits)
inline

◆ operator<=()

bool Gray::cUInt64::operator<= ( const cUInt64 n) const
inline

◆ operator==() [1/2]

bool Gray::cUInt64::operator== ( const cUInt64 n) const
inline

◆ operator==() [2/2]

bool Gray::cUInt64::operator== ( UNIT_t  n) const
inline

◆ operator>()

bool Gray::cUInt64::operator> ( const cUInt64 n) const
inline

◆ operator>>=()

cUInt64& Gray::cUInt64::operator>>= ( BIT_ENUM_t  uiBits)
inline

◆ operator^=()

cUInt64& Gray::cUInt64::operator^= ( const cUInt64 n)
inline

◆ operator|=()

cUInt64& Gray::cUInt64::operator|= ( const cUInt64 n)
inline

◆ SetBit()

void Gray::cUInt64::SetBit ( BIT_ENUM_t  uiBit)
inline

◆ SetPowerMod()

void Gray::cUInt64::SetPowerMod ( const cUInt64 base,
const cUInt64 exponent,
const cUInt64 modulus 
)

Set *this to 'base' to the power of 'exponent' then modulus. *this = ((base^exponent)modulus)

◆ SetRandomBits()

HRESULT Gray::cUInt64::SetRandomBits ( BIT_ENUM_t  nBits)

◆ SetRandomPrime()

int Gray::cUInt64::SetRandomPrime ( BIT_ENUM_t  nBits,
cThreadState pCancel = nullptr 
)

This function generates/finds/guesses a random prime.

Returns
Number of tries to get a prime.

◆ SetStr()

bool Gray::cUInt64::SetStr ( const char *  pszVal,
RADIX_t  nBaseRadix = 10,
const char **  ppszEnd = (const char**) nullptr 
)

Friends And Related Function Documentation

◆ cUInt64Tests

friend class cUInt64Tests
friend

Member Data Documentation

◆ k_UNIT_BITS

const unsigned Gray::cUInt64::k_UNIT_BITS = 64
static

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