5 #ifndef _INC_cBigInteger_H
6 #define _INC_cBigInteger_H
39 , m_bNegative(x.m_bNegative)
45 , m_bNegative(bNegative)
54 SetStr(pszStr, uRadix);
59 , m_bNegative(bNegative)
65 :
SUPER_t(nBlocks, pBlocks, bStatic)
66 , m_bNegative(bNegative)
83 ASSERT(!m_bNegative || !isZero());
88 ASSERT(!m_bNegative || !isZero());
89 return m_bNegative ? (-1) : 1;
102 return SUPER_t::CompareU(x);
109 return SUPER_t::Compare(x);
114 return (m_bNegative == x.m_bNegative) && get_Magnitude().IsEqual(x.
get_Magnitude());
119 if (get_BlocksUse() > 1)
134 return GetBlock(0) == ux;
148 return Compare(x) < 0;
152 return Compare(x) <= 0;
156 return Compare(x) >= 0;
160 return Compare(x) > 0;
163 template <
typename TYPE >
167 TYPE nVal = SUPER_t::get_ValS<TYPE>();
172 template <
typename TYPE >
176 return SUPER_t::get_ValUC<TYPE>();
183 bool SetStr(
const char* pszIn,
RADIX_t uRadix = 10,
const char** ppszEnd =
nullptr);
185 HRESULT SetBinaryBE(
const BYTE* pData,
size_t nSize,
bool bByteSign);
194 return SUPER_t::GetBinaryBE(pOut, nSizeOut);
201 HRESULT hRes = SUPER_t::SetCopySecure(val, assign);
202 this->put_Sign(this->get_Sign() * (1 - assign) + val.
get_Sign() * assign);
207 HRESULT hRes = SUPER_t::SwapSecure(X, Y, swap);
222 SUPER_t::SetZeroAll();
227 SUPER_t::SetNullVal();
234 SUPER_t::put_ValU(n);
238 m_bNegative = (n < 0);
239 SUPER_t::put_ValU((
UINTMAX_t)(m_bNegative ? (-n) : n));
241 template <
typename TYPE>
248 void SetBlocksStatic(BLOCK_ENUM_t nBlocks,
const BLOCK_t* pBlocks);
252 void OpAdd1(BLOCKI_t n);
253 void OpSubtract1(BLOCKI_t n);
259 this->put_Negative(
false);
260 SUPER_t::InitAdd(a, b);
266 this->put_Negative(
false);
267 return SUPER_t::InitSubtract(a, b);
271 InitSubtract(*
this, b);
275 return SUPER_t::OpSubtract(a);
297 return InitDivide(a, b, rJunkRemainder);
305 HRESULT InitModulusU(
const THIS_t& a,
const THIS_t& b);
309 BLOCK_t nVal = SUPER_t::GetModulusH(b);
312 if (this->isNegative() && nVal != 0)
362 InitSubtract(*
this, x);
366 InitMultiply(*
this, x);
384 if (m_bNegative && isZero())
396 m_bNegative = (nSign < 0);
407 m_bNegative = !m_bNegative;
415 void operator ++(
int)
423 void operator --(
int)
431 HRESULT SetPowerMod(
const THIS_t& base,
const THIS_t& exponent,
const THIS_t& modulus, OUT
cBigUnsigned* pRR);
439 return get_ValS<INT64>();
441 #ifndef USE_LONG_AS_INT64
444 return get_ValS<long>();
449 return get_ValS<int>();
453 return get_ValS<short>();
462 #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: cBigInteger.h:18
cBigInteger(INTMAX_t x)
Definition: cBigInteger.h:74
BLOCK_t GetModulusH(BLOCKH_t b) const
Definition: cBigInteger.h:307
cBigInteger(const THIS_t &x)
Definition: cBigInteger.h:37
COMPARE_t CompareU(BLOCK_t x) const
Definition: cBigInteger.h:98
void put_Negative(bool b=true)
Definition: cBigInteger.h:387
void put_Val(TYPE n)
Definition: cBigInteger.h:242
bool isNegative() const
Definition: cBigInteger.h:81
HRESULT InitDivide(const THIS_t &a, const cBigInteger &b)
Definition: cBigInteger.h:293
TYPE get_ValS() const
Definition: cBigInteger.h:164
void OpSubtract(const THIS_t &b)
Definition: cBigInteger.h:269
const cBigUnsigned & get_Magnitude() const
Definition: cBigInteger.h:91
COMPARE_t CompareMagnitude(const cBigUnsigned &x) const
Definition: cBigInteger.h:106
cBigInteger(BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks, bool bStatic, bool bNegative)
Definition: cBigInteger.h:64
cBigInteger(const cBigUnsigned &x, bool bNegative=false)
Definition: cBigInteger.h:43
void InitAdd1(const THIS_t &a, BLOCKI_t n)
Definition: cBigInteger.h:284
HRESULT InitModulus(const THIS_t &a, const THIS_t &b)
Definition: cBigInteger.h:299
void SetNullVal()
Definition: cBigInteger.h:224
HRESULT GetBinaryBE(BYTE *pOut, size_t nSizeOut) const
Definition: cBigInteger.h:191
TYPE get_Val() const
Definition: cBigInteger.h:173
void InitSubtract1(const THIS_t &a, BLOCKI_t n)
Definition: cBigInteger.h:278
void SetCopyInt(const cBigInteger &x)
Definition: cBigInteger.cpp:173
void FlipSign()
Definition: cBigInteger.h:399
cBigInteger(const char *pszStr, RADIX_t uRadix=10)
Definition: cBigInteger.h:50
static HRESULT GRAYCALL SwapSecure(THIS_t &X, THIS_t &Y, bool swap)
Definition: cBigInteger.h:205
cBigInteger()
Definition: cBigInteger.h:32
void put_ValU(UINTMAX_t n)
Definition: cBigInteger.h:230
void operator=(const THIS_t &x)
Definition: cBigInteger.h:214
HRESULT OpSubtractU(const cBigUnsigned &a)
Definition: cBigInteger.h:273
void put_Sign(int nSign)
Definition: cBigInteger.h:393
bool IsEqual(const THIS_t &x) const
Definition: cBigInteger.h:112
bool IsEqual(BLOCKI_t x) const
Definition: cBigInteger.h:116
void put_ValS(INTMAX_t n)
Definition: cBigInteger.h:236
void CheckNegativeZero()
Definition: cBigInteger.h:381
HRESULT SetCopySecure(const THIS_t &val, bool assign)
Definition: cBigInteger.h:199
HRESULT InitSubU(const cBigUnsigned &a, const cBigUnsigned &b)
Definition: cBigInteger.h:263
HRESULT InitDivide(const cBigInteger ÷nd, const cBigInteger &divisor, OUT cBigInteger &remainder)
Definition: cBigInteger.cpp:302
void SetZeroAll()
Definition: cBigInteger.h:219
cBigInteger(UINTMAX_t x)
Definition: cBigInteger.h:73
void InitSubtract(const cBigInteger &a, const cBigInteger &b)
Definition: cBigInteger.cpp:235
int get_Sign() const
Definition: cBigInteger.h:86
cBigInteger(UINT32 x)
Definition: cBigInteger.h:76
void InitAddU(const cBigUnsigned &a, const cBigUnsigned &b)
Definition: cBigInteger.h:256
cBigInteger(INT32 x)
Definition: cBigInteger.h:77
void InitMultiply(const cBigInteger &a, const cBigInteger &b)
Definition: cBigInteger.cpp:286
cBigInteger(BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks, bool bNegative)
Definition: cBigInteger.h:57
void InitAdd(const cBigInteger &a, const cBigInteger &b)
Definition: cBigInteger.cpp:186
HRESULT SetBinaryBE(const cMemBlock &b, bool bByteSign)
Definition: cBigInteger.h:186
UNITTEST_FRIEND(cBigInteger)
Definition: cBigUnsigned.h:22
Definition: cBitArray.h:28
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
INT32 BLOCKI_t
The biggest signed type I can do atomic math on.
Definition: cBitArray.h:47
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
BYTE * get_DataBytes() const noexcept
Definition: cMem.h:354
size_t get_DataSize() const noexcept
Definition: cMem.h:344
cVecT2< TYPE > operator*(const TYPE nVal, const cVecT2< TYPE > &v2)
Definition: cVecT.h:522
UNITTEST2_PREDEF(cQuadtree)
int COMPARE_t
result of compare. 0=same, 1=a>b, -1=a<b
Definition: cValT.h:17
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
WORD RADIX_t
Base for convert of numbers to strings. e.g. 10 base vs 16 base hex numbers.
Definition: StrChar.h:27
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
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_Less
VARCMP_LT.
Definition: cValT.h:22
bool operator<=(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:238