5 #ifndef _INC_cBigUnsigned_H
6 #define _INC_cBigUnsigned_H
55 :
SUPER_t(nBlocks, pBlocks, bStatic)
64 SetStr(pszStr, nBaseRadix);
80 void SetBlockSizeInit(BLOCK_ENUM_t nBlocks,
const BLOCK_t* pBlocks);
86 return get_BlocksUse() == 0;
93 return(GetBlockInt(0) & 1);
96 template <
typename TYPE >
101 size_t nSizeAvail = get_BlocksCap() *
sizeof(
BLOCK_t);
106 if (nSizeAvail <
sizeof(
TYPE))
109 ::memcpy(&uVal, get_BlockPtrC(), nSizeAvail);
113 return(*((
const TYPE*)get_BlockPtrC()));
116 template <
typename TYPE >
122 if (
sizeof(
TYPE) < nBytes)
124 ReturnError(DISP_E_OVERFLOW,
"cBigUnsigned::get_ValS: Value is too big to fit in the requested type");
127 return get_ValU<TYPE>();
129 template <
typename TYPE >
133 TYPE uVal = get_ValUC<TYPE>();
136 ReturnError(DISP_E_OVERFLOW,
"cBigUnsigned::get_ValS: Value is too big to fit in the requested signed type");
141 template <
typename TYPE >
145 return get_ValUC<TYPE>();
168 bool SetStr(
const char* pszVal,
RADIX_t nBaseRadix = 10,
const char** ppszEnd = (
const char**)
nullptr);
176 template <
typename TYPE>
190 void OpBitShiftLeft1(BLOCK_t nBitMask = 0);
194 return InitBitShiftLeft(*
this, b);
199 return InitBitShiftRight(*
this, b);
203 void OpAdd1(BLOCK_t nVal);
204 HRESULT OpSubtract1(BLOCK_t nVal);
216 return InitSubtract(*
this, b);
219 static void MultiplyHelper(BLOCK_t* pDst, BLOCK_ENUM_t nBlocks,
const cBigUnsigned& rSrc, BLOCK_t nMult);
224 BLOCK_t GetModulusH(BLOCKH_t b)
const;
225 BLOCKH_t InitDivideH(
const cBigUnsigned& a, BLOCKH_t b);
231 return InitDivide(a, b, rJunkRemainder);
247 BLOCK_t get_MontgomeryInit()
const;
248 void SetMontMul(THIS_t& rDst,
const THIS_t& B,
const THIS_t& N, BLOCK_t mm);
249 void SetMontRedux(THIS_t& rDst,
const THIS_t& N, BLOCK_t mm);
251 void SetPower(
const THIS_t& base,
const THIS_t& exponent);
252 HRESULT SetPowerMod(
const THIS_t& base,
const THIS_t& exponent,
const THIS_t& modulus, OUT THIS_t* pRR =
nullptr);
369 InitSubtract(*
this, x);
377 InitMultiply(*
this, x);
381 InitMultiplyH(*
this, x);
392 (void)InitDivideH(*
this, n);
403 put_ValU(InitDivideH(*
this, n));
407 InitBitAnd(*
this, x);
415 InitBitXor(*
this, x);
417 void operator <<=(
int b)
421 void operator >>=(
int b)
432 void operator ++(
int)
441 void operator --(
int)
454 return get_ValS<INT64>();
457 #ifndef USE_LONG_AS_INT64
460 return get_ValS<long>();
465 return get_ValS<int>();
469 return get_ValS<short>();
478 #ifndef USE_LONG_AS_INT64
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
Using X files without the sources and the makefile How to use you just create a debug directory e g
Definition: Readme.txt:21
#define TYPE
Definition: StrT.cpp:38
UINT64 UINTMAX_t
Definition: SysTypes.h:435
INT64 INTMAX_t
Definition: SysTypes.h:434
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cBigUnsigned.h:22
TYPE get_Val() const
Definition: cBigUnsigned.h:142
HRESULT InitDivide(const cBigUnsigned &a, const cBigUnsigned &b, OUT cBigUnsigned &remainder)
Definition: cBigUnsMulDiv.cpp:1078
bool isOdd() const
Definition: cBigUnsigned.h:88
cBigUnsigned(INT32 x)
Definition: cBigUnsigned.h:77
HRESULT InitBitShiftLeft(const cBigUnsigned &a, int b)
Definition: cBigUnsigned.cpp:325
HRESULT OpSubtract1(BLOCK_t nVal)
Definition: cBigUnsigned.cpp:485
void InitSubtract1(const THIS_t &a, BLOCK_t n)
Definition: cBigUnsigned.h:205
cBigUnsigned(BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks)
Definition: cBigUnsigned.h:49
HRESULT InitSubtract(const cBigUnsigned &a, const cBigUnsigned &b)
Definition: cBigUnsigned.cpp:589
TYPE get_ValUC() const
Definition: cBigUnsigned.h:117
void InitBitAnd(const cBigUnsigned &a, const cBigUnsigned &b)
Definition: cBigUnsigned.cpp:223
cBigUnsigned(UINTMAX_t x)
Definition: cBigUnsigned.h:73
cBigUnsigned(INTMAX_t x)
Definition: cBigUnsigned.h:74
cBigUnsigned(const char *pszStr, RADIX_t nBaseRadix=10)
Definition: cBigUnsigned.h:61
HRESULT InitDivide(const THIS_t &a, const THIS_t &b)
Definition: cBigUnsigned.h:227
cBigUnsigned(const cBigUnsigned &x)
Definition: cBigUnsigned.h:39
cBigUnsigned()
Definition: cBigUnsigned.h:35
void InitBitOr(const cBigUnsigned &a, const cBigUnsigned &b)
Definition: cBigUnsigned.cpp:240
HRESULT OpBitShiftLeft(BIT_ENUM_t b)
Definition: cBigUnsigned.h:191
cBigUnsigned(BIT_ENUM_t nBits, BLOCK_t uValMask)
Definition: cBigUnsigned.h:45
cBigUnsigned(UINT32 x)
Definition: cBigUnsigned.h:76
void InitMultiplyH(const cBigUnsigned &a, BLOCKH_t b)
Definition: cBigUnsMulDiv.cpp:972
TYPE get_ValS() const
Definition: cBigUnsigned.h:130
BLOCKH_t InitDivideH(const cBigUnsigned &a, BLOCKH_t b)
Definition: cBigUnsMulDiv.cpp:1046
HRESULT InitBitShiftRight(const cBigUnsigned &a, int b)
Definition: cBigUnsigned.cpp:401
HRESULT put_ValS(INTMAX_t n)
Definition: cBigUnsigned.cpp:211
HRESULT OpBitShiftRight(BIT_ENUM_t b)
Definition: cBigUnsigned.h:196
void InitMultiply(const cBigUnsigned &a, const cBigUnsigned &b)
Definition: cBigUnsMulDiv.cpp:911
cBigUnsigned(BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks, bool bStatic)
Definition: cBigUnsigned.h:54
UNITTEST_FRIEND(cBigUnsigned)
void InitAdd(const cBigUnsigned &a, const cBigUnsigned &b)
Definition: cBigUnsigned.cpp:510
bool isZero() const
Definition: cBigUnsigned.h:82
HRESULT OpSubtract(const THIS_t &b)
Definition: cBigUnsigned.h:214
void OpAdd1(BLOCK_t nVal)
Definition: cBigUnsigned.cpp:465
HRESULT InitModulus(const THIS_t &a, const THIS_t &b)
Definition: cBigUnsigned.h:233
~cBigUnsigned()
Definition: cBigUnsigned.h:67
TYPE get_ValU() const
Definition: cBigUnsigned.h:97
void put_Val(TYPE n)
Definition: cBigUnsigned.h:177
void InitBitXor(const cBigUnsigned &a, const cBigUnsigned &b)
Definition: cBigUnsigned.cpp:274
unsigned int BLOCK_ENUM_t
Type for the index of a BLOCK_t in the array. NOT bits BIT_ENUM_t.
Definition: cBitArray.h:78
UINT32 BLOCK_t
The biggest unsigned type I can do atomic math on for this architecture.
Definition: cBitArray.h:46
WORD BLOCKH_t
half sized BLOCK_t for multiplication overflows.
Definition: cBitArray.h:48
Definition: cBitArray.h:416
Definition: cThreadLock.h:137
cVecT2< TYPE > operator*(const TYPE nVal, const cVecT2< TYPE > &v2)
Definition: cVecT.h:522
UNITTEST2_PREDEF(cQuadtree)
cUInt64 operator|(const cUInt64 &roUI64_1, const cUInt64 &roUI64_2)
Definition: cUInt64.h:377
int COMPARE_t
result of compare. 0=same, 1=a>b, -1=a<b
Definition: cValT.h:17
BITOP_TYPE
Definition: cBits.h:22
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
void operator>>(cArchive &ar, cStringT< _TYPE_CH > &pOb)
Definition: cString.h:678
cUInt64 operator^(const cUInt64 &roUI64_1, const cUInt64 &roUI64_2)
Definition: cUInt64.h:391
WORD RADIX_t
Base for convert of numbers to strings. e.g. 10 base vs 16 base hex numbers.
Definition: StrChar.h:27
unsigned int BIT_ENUM_t
Enumerate number of bits or address a single bit in some array of bits.
Definition: cBits.h:20
bool operator<(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:234
bool operator>=(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:246
cStringA operator+(const char *pStr1, const cStringA &s2)
Definition: cString.h:642
void operator<<(cArchive &ar, const cStringT< _TYPE_CH > &pOb)
Definition: cString.h:680
bool operator!=(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:254
bool operator==(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:250
bool operator>(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:242
@ COMPARE_Equal
VARCMP_EQ.
Definition: cValT.h:23
bool operator<=(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:238
cUInt64 operator&(const cUInt64 &roUI64_1, const cUInt64 &roUI64_2)
Definition: cUInt64.h:384
static constexpr size_t GetSizeBytes(BIT_ENUM_t nBits) noexcept
Definition: cBits.h:54