14 : bigits_(bigits_buffer_, kBigitCapacity), used_digits_(0), exponent_(0) {
23 return 8 *
sizeof(value);
31 if (value == 0)
return;
40 const int kUInt64Size = 64;
43 if (value == 0)
return;
45 int needed_bigits = kUInt64Size /
kBigitSize + 1;
47 for (
int i = 0;
i < needed_bigits; ++
i) {
73 for (
int i = from;
i < from + digits_to_read; ++
i) {
74 int digit = buffer[
i] -
'0';
75 DCHECK(0 <= digit && digit <= 9);
76 result = result * 10 + digit;
86 int length = value.
length();
96 uint64_t digits =
ReadUInt64(value, pos, length);
104 if (
'0' <= c && c <=
'9')
return c -
'0';
105 if (
'a' <= c && c <=
'f')
return 10 + c -
'a';
106 if (
'A' <= c && c <=
'F')
return 10 + c -
'A';
114 int length = value.
length();
116 int needed_bigits = length * 4 /
kBigitSize + 1;
118 int string_index = length - 1;
119 for (
int i = 0;
i < needed_bigits - 1; ++
i) {
121 Chunk current_bigit = 0;
123 current_bigit +=
HexCharValue(value[string_index--]) << (j * 4);
129 Chunk most_significant_bigit = 0;
130 for (
int j = 0; j <= string_index; ++j) {
131 most_significant_bigit <<= 4;
134 if (most_significant_bigit != 0) {
143 if (operand == 0)
return;
204 DCHECK((borrow == 0) || (borrow == 1));
209 while (borrow != 0) {
229 if (factor == 1)
return;
255 if (factor == 1)
return;
262 uint64_t low = factor & 0xFFFFFFFF;
263 uint64_t high = factor >> 32;
265 uint64_t product_low = low *
bigits_[
i];
266 uint64_t product_high = high *
bigits_[
i];
292 const uint32_t kFive10 = kFive9 * 5;
293 const uint32_t kFive11 = kFive10 * 5;
294 const uint32_t kFive12 = kFive11 * 5;
295 const uint32_t kFive13 = kFive12 * 5;
297 { kFive1, kFive2, kFive3, kFive4, kFive5, kFive6,
298 kFive7, kFive8, kFive9, kFive10, kFive11, kFive12 };
301 if (exponent == 0)
return;
305 int remaining_exponent = exponent;
306 while (remaining_exponent >= 27) {
308 remaining_exponent -= 27;
310 while (remaining_exponent >= 13) {
312 remaining_exponent -= 13;
314 if (remaining_exponent > 0) {
351 int bigit_index1 =
i;
352 int bigit_index2 = 0;
354 while (bigit_index1 >= 0) {
357 accumulator +=
static_cast<DoubleChunk>(chunk1) * chunk2;
366 int bigit_index2 =
i - bigit_index1;
372 accumulator +=
static_cast<DoubleChunk>(chunk1) * chunk2;
395 DCHECK(power_exponent >= 0);
396 if (power_exponent == 0) {
405 while ((base & 1) == 0) {
411 while (tmp_base != 0) {
415 int final_size = bit_size * power_exponent;
421 while (power_exponent >= mask) mask <<= 1;
427 uint64_t this_value = base;
429 bool delayed_multipliciation =
false;
430 const uint64_t max_32bits = 0xFFFFFFFF;
431 while (mask != 0 && this_value <= max_32bits) {
432 this_value = this_value * this_value;
435 if ((power_exponent & mask) != 0) {
436 uint64_t base_bits_mask =
437 ~((
static_cast<uint64_t
>(1) << (64 - bit_size)) - 1);
438 bool high_bits_zero = (this_value & base_bits_mask) == 0;
439 if (high_bits_zero) {
442 delayed_multipliciation =
true;
448 if (delayed_multipliciation) {
455 if ((power_exponent & mask) != 0) {
505 int quotient = this_bigit / other_bigit;
512 int division_estimate = this_bigit / (other_bigit + 1);
513 result += division_estimate;
516 if (other_bigit * (division_estimate + 1) > this_bigit) {
534 while (number != 0) {
543 DCHECK(0 <= value && value <= 16);
544 if (value < 10)
return value +
'0';
545 return value - 10 +
'A';
556 if (buffer_size < 2)
return false;
562 int needed_chars = (
BigitLength() - 1) * kHexCharsPerBigit +
564 if (needed_chars > buffer_size)
return false;
565 int string_index = needed_chars - 1;
566 buffer[string_index--] =
'\0';
568 for (
int j = 0; j < kHexCharsPerBigit; ++j) {
569 buffer[string_index--] =
'0';
574 for (
int j = 0; j < kHexCharsPerBigit; ++j) {
581 while (most_significant_bigit != 0) {
582 buffer[string_index--] =
HexCharOfValue(most_significant_bigit & 0xF);
583 most_significant_bigit >>= 4;
601 if (bigit_length_a < bigit_length_b)
return -1;
602 if (bigit_length_a > bigit_length_b)
return +1;
606 if (bigit_a < bigit_b)
return -1;
607 if (bigit_a > bigit_b)
return +1;
637 Chunk sum = chunk_a + chunk_b;
638 if (sum > chunk_c + borrow) {
641 borrow = chunk_c + borrow - sum;
642 if (borrow > 1)
return -1;
646 if (borrow == 0)
return 0;
689 for (
int i = 0;
i < zero_digits; ++
i) {
702 DCHECK(shift_amount >= 0);
726 for (
int i = 0;
i < factor; ++
i) {
743 if (borrow == 0)
return;
void ShiftLeft(int shift_amount)
static const int kChunkSize
void AddBignum(const Bignum &other)
void BigitsShiftLeft(int shift_amount)
static const int kBigitCapacity
void SubtractBignum(const Bignum &other)
static const int kBigitSize
void AssignUInt16(uint16_t value)
void Align(const Bignum &other)
void AssignBignum(const Bignum &other)
static bool Equal(const Bignum &a, const Bignum &b)
static const int kDoubleChunkSize
void AssignHexString(Vector< const char > value)
void MultiplyByPowerOfTen(int exponent)
static bool LessEqual(const Bignum &a, const Bignum &b)
static const Chunk kBigitMask
uint16_t DivideModuloIntBignum(const Bignum &other)
void AssignPowerUInt16(uint16_t base, int exponent)
void AssignDecimalString(Vector< const char > value)
void SubtractTimes(const Bignum &other, int factor)
void MultiplyByUInt64(uint64_t factor)
void AssignUInt64(uint64_t value)
void AddUInt64(uint64_t operand)
Chunk BigitAt(int index) const
static int PlusCompare(const Bignum &a, const Bignum &b, const Bignum &c)
static int Compare(const Bignum &a, const Bignum &b)
void MultiplyByUInt32(uint32_t factor)
bool ToHexString(char *buffer, int buffer_size) const
void EnsureCapacity(int size)
#define DCHECK(condition)
#define V8_2PART_UINT64_C(a, b)
static int SizeInHexChars(S number)
static int BitSize(S value)
static LifetimePosition Min(LifetimePosition a, LifetimePosition b)
static char HexCharOfValue(int value)
static const int kMaxUint64DecimalDigits
static LifetimePosition Max(LifetimePosition a, LifetimePosition b)
static uint64_t ReadUInt64(Vector< const char > buffer, int from, int digits_to_read)
static int HexCharValue(char c)
Debugger support for the V8 JavaScript engine.