Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 | 2 |
| 3 #include "vm/bigint_operations.h" | 3 #include "vm/bigint_operations.h" |
| 4 | 4 |
| 5 #include "platform/utils.h" | 5 #include "platform/utils.h" |
| 6 | 6 |
| 7 #include "vm/double_internals.h" | 7 #include "vm/double_internals.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/zone.h" | 10 #include "vm/zone.h" |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 ASSERT(static_cast<Chunk>(kDivisorValue) < kDigitMaxValue); | 383 ASSERT(static_cast<Chunk>(kDivisorValue) < kDigitMaxValue); |
| 384 ASSERT(Smi::IsValid(kDivisorValue)); | 384 ASSERT(Smi::IsValid(kDivisorValue)); |
| 385 const Bigint& divisor = Bigint::Handle(NewFromInt64(kDivisorValue)); | 385 const Bigint& divisor = Bigint::Handle(NewFromInt64(kDivisorValue)); |
| 386 | 386 |
| 387 // Rest contains the remaining bigint that needs to be printed. | 387 // Rest contains the remaining bigint that needs to be printed. |
| 388 Bigint& rest = Bigint::Handle(bigint.raw()); | 388 Bigint& rest = Bigint::Handle(bigint.raw()); |
| 389 Bigint& quotient = Bigint::Handle(); | 389 Bigint& quotient = Bigint::Handle(); |
| 390 Bigint& remainder = Bigint::Handle(); | 390 Bigint& remainder = Bigint::Handle(); |
| 391 while (!rest.IsZero()) { | 391 while (!rest.IsZero()) { |
| 392 DivideRemainder(rest, divisor, "ient, &remainder); | 392 DivideRemainder(rest, divisor, "ient, &remainder); |
| 393 ASSERT(remainder.Length() == 1); | 393 ASSERT(remainder.Length() <= 1); |
| 394 intptr_t part = static_cast<intptr_t>(remainder.GetChunkAt(0)); | 394 intptr_t part = 0; |
|
kasperl
2012/03/07 12:47:01
intptr_t part = (remainder.Length() == 1)
? sta
floitsch
2012/03/07 12:51:26
Done.
| |
| 395 if (remainder.Length() == 1) { | |
| 396 part = static_cast<intptr_t>(remainder.GetChunkAt(0)); | |
| 397 } | |
| 395 for (int i = 0; i < kPowerOfTen; i++) { | 398 for (int i = 0; i < kPowerOfTen; i++) { |
| 396 result[result_pos++] = '0' + (part % 10); | 399 result[result_pos++] = '0' + (part % 10); |
| 397 part /= 10; | 400 part /= 10; |
| 398 } | 401 } |
| 399 ASSERT(part == 0); | 402 ASSERT(part == 0); |
| 400 rest = quotient.raw(); | 403 rest = quotient.raw(); |
| 401 } | 404 } |
| 402 // Move the resulting position back until we don't have any zeroes anymore. | 405 // Move the resulting position back until we don't have any zeroes anymore. |
| 403 // This is done so that we can remove all leading zeroes. | 406 // This is done so that we can remove all leading zeroes. |
| 404 while (result_pos > 1 && result[result_pos - 1] == '0') { | 407 while (result_pos > 1 && result[result_pos - 1] == '0') { |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1502 int BigintOperations::CountBits(Chunk digit) { | 1505 int BigintOperations::CountBits(Chunk digit) { |
| 1503 int result = 0; | 1506 int result = 0; |
| 1504 while (digit != 0) { | 1507 while (digit != 0) { |
| 1505 digit >>= 1; | 1508 digit >>= 1; |
| 1506 result++; | 1509 result++; |
| 1507 } | 1510 } |
| 1508 return result; | 1511 return result; |
| 1509 } | 1512 } |
| 1510 | 1513 |
| 1511 } // namespace dart | 1514 } // namespace dart |
| OLD | NEW |