OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/bignum.h" | 5 #include "src/bignum.h" |
6 #include "src/utils.h" | 6 #include "src/utils.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 | 10 |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 DCHECK(number > 0); | 532 DCHECK(number > 0); |
533 int result = 0; | 533 int result = 0; |
534 while (number != 0) { | 534 while (number != 0) { |
535 number >>= 4; | 535 number >>= 4; |
536 result++; | 536 result++; |
537 } | 537 } |
538 return result; | 538 return result; |
539 } | 539 } |
540 | 540 |
541 | 541 |
542 static char HexCharOfValue(int value) { | |
543 DCHECK(0 <= value && value <= 16); | |
544 if (value < 10) return value + '0'; | |
545 return value - 10 + 'A'; | |
546 } | |
547 | |
548 | |
549 bool Bignum::ToHexString(char* buffer, int buffer_size) const { | 542 bool Bignum::ToHexString(char* buffer, int buffer_size) const { |
550 DCHECK(IsClamped()); | 543 DCHECK(IsClamped()); |
551 // Each bigit must be printable as separate hex-character. | 544 // Each bigit must be printable as separate hex-character. |
552 DCHECK(kBigitSize % 4 == 0); | 545 DCHECK(kBigitSize % 4 == 0); |
553 const int kHexCharsPerBigit = kBigitSize / 4; | 546 const int kHexCharsPerBigit = kBigitSize / 4; |
554 | 547 |
555 if (used_digits_ == 0) { | 548 if (used_digits_ == 0) { |
556 if (buffer_size < 2) return false; | 549 if (buffer_size < 2) return false; |
557 buffer[0] = '0'; | 550 buffer[0] = '0'; |
558 buffer[1] = '\0'; | 551 buffer[1] = '\0'; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 bigits_[i] = difference & kBigitMask; | 738 bigits_[i] = difference & kBigitMask; |
746 borrow = difference >> (kChunkSize - 1); | 739 borrow = difference >> (kChunkSize - 1); |
747 } | 740 } |
748 Clamp(); | 741 Clamp(); |
749 DCHECK(Bignum::Equal(a, *this)); | 742 DCHECK(Bignum::Equal(a, *this)); |
750 } | 743 } |
751 | 744 |
752 | 745 |
753 } // namespace internal | 746 } // namespace internal |
754 } // namespace v8 | 747 } // namespace v8 |
OLD | NEW |