| 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/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "platform/utils.h" | 6 #include "platform/utils.h" |
| 7 | 7 |
| 8 #include "vm/double_internals.h" | 8 #include "vm/double_internals.h" |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 } | 686 } |
| 687 ASSERT(FitsIntoInt64(bigint)); | 687 ASSERT(FitsIntoInt64(bigint)); |
| 688 int64_t value = AbsToUint64(bigint); | 688 int64_t value = AbsToUint64(bigint); |
| 689 if (bigint.IsNegative()) { | 689 if (bigint.IsNegative()) { |
| 690 value = -value; | 690 value = -value; |
| 691 } | 691 } |
| 692 return value; | 692 return value; |
| 693 } | 693 } |
| 694 | 694 |
| 695 | 695 |
| 696 uint32_t BigintOperations::TruncateToUint32(const Bigint& bigint) { |
| 697 uint32_t value = 0; |
| 698 for (intptr_t i = bigint.Length() - 1; i >= 0; i--) { |
| 699 value <<= kDigitBitSize; |
| 700 value += static_cast<uint32_t>(bigint.GetChunkAt(i)); |
| 701 } |
| 702 return value; |
| 703 } |
| 704 |
| 705 |
| 696 bool BigintOperations::AbsFitsIntoUint64(const Bigint& bigint) { | 706 bool BigintOperations::AbsFitsIntoUint64(const Bigint& bigint) { |
| 697 intptr_t b_length = bigint.Length(); | 707 intptr_t b_length = bigint.Length(); |
| 698 intptr_t num_bits = CountBits(bigint.GetChunkAt(b_length - 1)); | 708 intptr_t num_bits = CountBits(bigint.GetChunkAt(b_length - 1)); |
| 699 num_bits += (kDigitBitSize * (b_length - 1)); | 709 num_bits += (kDigitBitSize * (b_length - 1)); |
| 700 if (num_bits > 64) return false; | 710 if (num_bits > 64) return false; |
| 701 return true; | 711 return true; |
| 702 } | 712 } |
| 703 | 713 |
| 704 | 714 |
| 705 bool BigintOperations::FitsIntoUint64(const Bigint& bigint) { | 715 bool BigintOperations::FitsIntoUint64(const Bigint& bigint) { |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1798 intptr_t BigintOperations::CountBits(Chunk digit) { | 1808 intptr_t BigintOperations::CountBits(Chunk digit) { |
| 1799 intptr_t result = 0; | 1809 intptr_t result = 0; |
| 1800 while (digit != 0) { | 1810 while (digit != 0) { |
| 1801 digit >>= 1; | 1811 digit >>= 1; |
| 1802 result++; | 1812 result++; |
| 1803 } | 1813 } |
| 1804 return result; | 1814 return result; |
| 1805 } | 1815 } |
| 1806 | 1816 |
| 1807 } // namespace dart | 1817 } // namespace dart |
| OLD | NEW |