15 #ifndef RAPIDJSON_BIGINTEGER_H_ 16 #define RAPIDJSON_BIGINTEGER_H_ 18 #include "../rapidjson.h" 20 #if defined(_MSC_VER) && defined(_M_AMD64) 22 #pragma intrinsic(_umul128) 44 const size_t kMaxDigitPerIteration = 19;
45 while (
length >= kMaxDigitPerIteration) {
47 length -= kMaxDigitPerIteration;
48 i += kMaxDigitPerIteration;
73 for (
size_t i = 0; i <
count_ - 1; i++) {
88 if (u == 0)
return *
this = 0;
89 if (u == 1)
return *
this;
90 if (*
this == 1)
return *
this = u;
93 for (
size_t i = 0; i <
count_; i++) {
106 if (u == 0)
return *
this = 0;
107 if (u == 1)
return *
this;
108 if (*
this == 1)
return *
this = u;
111 for (
size_t i = 0; i <
count_; i++) {
118 digits_[i] = (p0 & 0xFFFFFFFF) | (
p1 << 32);
129 if (
IsZero() || shift == 0)
return *
this;
132 size_t interShift = shift %
kTypeBit;
135 if (interShift == 0) {
141 for (
size_t i =
count_; i > 0; i--)
169 5 * 5 * 5 * 5 * 5 * 5,
170 5 * 5 * 5 * 5 * 5 * 5 * 5,
171 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
172 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
173 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
174 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
175 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5
177 if (
exp == 0)
return *
this;
179 for (;
exp >= 13;
exp -= 13) *
this *= static_cast<uint32_t>(1220703125u);
180 if (
exp > 0) *
this *= kPow5[
exp - 1];
191 if (cmp < 0) {
a = &rhs;
b =
this; ret =
true; }
192 else {
a =
this;
b = &rhs; ret =
false; }
195 for (
size_t i = 0; i <
a->count_; i++) {
199 borrow = (d >
a->digits_[i]) ? 1 : 0;
212 for (
size_t i =
count_; i-- > 0;)
229 unsigned exp =
static_cast<unsigned>(
end - begin);
241 for (
const char*
p = begin;
p !=
end; ++
p) {
243 r =
r * 10u +
static_cast<unsigned>(*
p -
'0');
250 #if defined(_MSC_VER) && defined(_M_AMD64) 255 #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) 256 __extension__
typedef unsigned __int128 uint128;
257 uint128
p =
static_cast<uint128
>(
a) * static_cast<uint128>(
b);
259 *outHigh =
static_cast<uint64_t>(
p >> 64);
262 const uint64_t a0 =
a & 0xFFFFFFFF,
a1 =
a >> 32, b0 =
b & 0xFFFFFFFF, b1 =
b >> 32;
267 x3 += (
static_cast<uint64_t>(1) << 32);
268 uint64_t lo = (x1 << 32) + (x0 & 0xFFFFFFFF);
290 #endif // RAPIDJSON_BIGINTEGER_H_ static const size_t kBitCount
Definition: biginteger.h:279
bool operator==(const Type rhs) const
Definition: biginteger.h:158
bool operator==(const BigInteger &rhs) const
Definition: biginteger.h:154
static const size_t kCapacity
Definition: biginteger.h:280
static uint64_t ParseUint64(const char *begin, const char *end)
Definition: biginteger.h:239
Definition: biginteger.h:28
GLfixed GLfixed x2
Definition: glsym_gl.h:1051
bool Difference(const BigInteger &rhs, BigInteger *out) const
Definition: biginteger.h:186
GLdouble GLdouble GLdouble r
Definition: glext.h:6406
void PushBack(Type digit)
Definition: biginteger.h:234
BigInteger & operator=(uint64_t u)
Definition: biginteger.h:64
int memcmp(const void *s1, const void *s2, unsigned int length)
Definition: compat_ctype.c:51
struct passwd out
Definition: missing_libc_functions.c:51
BigInteger & operator<<=(size_t shift)
Definition: biginteger.h:128
bool IsZero() const
Definition: biginteger.h:221
#define exp(a)
Definition: math.h:32
uint64_t Type
Definition: biginteger.h:30
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:119
const GLubyte * c
Definition: glext.h:9812
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
void AppendDecimal64(const char *begin, const char *end)
Definition: biginteger.h:224
BigInteger(uint64_t u)
Definition: biginteger.h:36
size_t count_
Definition: biginteger.h:284
Type GetDigit(size_t index) const
Definition: biginteger.h:220
BigInteger & operator+=(uint64_t u)
Definition: biginteger.h:70
BigInteger(const BigInteger &rhs)
Definition: biginteger.h:32
float4 p1
Definition: notHere.h:1
f32 a0
Definition: gx_regdef.h:5094
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:402
Definition: document.h:391
GLfloat GLfloat p
Definition: glext.h:9809
static uint64_t MulAdd64(uint64_t a, uint64_t b, uint64_t k, uint64_t *outHigh)
Definition: biginteger.h:249
BigInteger & operator*=(uint32_t u)
Definition: biginteger.h:105
GLuint index
Definition: glext.h:6671
f32 a1
Definition: gx_regdef.h:5095
BigInteger & MultiplyPow5(unsigned exp)
Definition: biginteger.h:162
BigInteger(const char *decimals, size_t length)
Definition: biginteger.h:40
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:116
static int digit(int c)
Definition: lstrlib.c:1180
BigInteger & operator*=(uint64_t u)
Definition: biginteger.h:87
Type digits_[kCapacity]
Definition: biginteger.h:283
size_t GetCount() const
Definition: biginteger.h:219
GLuint GLuint end
Definition: glext.h:6292
int Compare(const BigInteger &rhs) const
Definition: biginteger.h:208
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:289
GLintptr offset
Definition: glext.h:6560
void * memset(void *b, int c, size_t len)
Definition: string.c:7
unsigned __int64 uint64_t
Definition: stdint.h:136
GLenum GLuint GLenum GLsizei length
Definition: glext.h:6233
unsigned int uint32_t
Definition: stdint.h:126
static const size_t kTypeBit
Definition: biginteger.h:281
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844
BigInteger & operator=(const BigInteger &rhs)
Definition: biginteger.h:55
void * memcpy(void *dst, const void *src, size_t len)
Definition: string.c:26