]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/double-conversion-bignum.h
ICU-66108.tar.gz
[apple/icu.git] / icuSources / i18n / double-conversion-bignum.h
index d39a3dee010d8b315e6a19ad19be2659e91aca5f..bae900a15a742052e9cbca406622d6e31725772b 100644 (file)
@@ -53,26 +53,27 @@ class Bignum {
   // exponent.
   static const int kMaxSignificantBits = 3584;
 
-  Bignum();
-  void AssignUInt16(uint16_t value);
+  Bignum() : used_bigits_(0), exponent_(0) {}
+
+  void AssignUInt16(const uint16_t value);
   void AssignUInt64(uint64_t value);
   void AssignBignum(const Bignum& other);
 
-  void AssignDecimalString(Vector<const char> value);
-  void AssignHexString(Vector<const char> value);
+  void AssignDecimalString(const Vector<const char> value);
+  void AssignHexString(const Vector<const char> value);
 
-  void AssignPowerUInt16(uint16_t base, int exponent);
+  void AssignPowerUInt16(uint16_t base, const int exponent);
 
-  void AddUInt64(uint64_t operand);
+  void AddUInt64(const uint64_t operand);
   void AddBignum(const Bignum& other);
   // Precondition: this >= other.
   void SubtractBignum(const Bignum& other);
 
   void Square();
-  void ShiftLeft(int shift_amount);
-  void MultiplyByUInt32(uint32_t factor);
-  void MultiplyByUInt64(uint64_t factor);
-  void MultiplyByPowerOfTen(int exponent);
+  void ShiftLeft(const int shift_amount);
+  void MultiplyByUInt32(const uint32_t factor);
+  void MultiplyByUInt64(const uint64_t factor);
+  void MultiplyByPowerOfTen(const int exponent);
   void Times10() { return MultiplyByUInt32(10); }
   // Pseudocode:
   //  int result = this / other;
@@ -80,7 +81,7 @@ class Bignum {
   // In the worst case this function is in O(this/other).
   uint16_t DivideModuloIntBignum(const Bignum& other);
 
-  bool ToHexString(char* buffer, int buffer_size) const;
+  bool ToHexString(char* buffer, const int buffer_size) const;
 
   // Returns
   //  -1 if a < b,
@@ -124,33 +125,40 @@ class Bignum {
   // grow. There are no checks if the stack-allocated space is sufficient.
   static const int kBigitCapacity = kMaxSignificantBits / kBigitSize;
 
-  void EnsureCapacity(int size) {
+  static void EnsureCapacity(const int size) {
     if (size > kBigitCapacity) {
-      UNREACHABLE();
+      DOUBLE_CONVERSION_UNREACHABLE();
     }
   }
   void Align(const Bignum& other);
   void Clamp();
-  bool IsClamped() const;
-  void Zero();
+  bool IsClamped() const {
+    return used_bigits_ == 0 || RawBigit(used_bigits_ - 1) != 0;
+  }
+  void Zero() {
+    used_bigits_ = 0;
+    exponent_ = 0;
+  }
   // Requires this to have enough capacity (no tests done).
-  // Updates used_digits_ if necessary.
+  // Updates used_bigits_ if necessary.
   // shift_amount must be < kBigitSize.
-  void BigitsShiftLeft(int shift_amount);
-  // BigitLength includes the "hidden" digits encoded in the exponent.
-  int BigitLength() const { return used_digits_ + exponent_; }
-  Chunk BigitAt(int index) const;
-  void SubtractTimes(const Bignum& other, int factor);
-
+  void BigitsShiftLeft(const int shift_amount);
+  // BigitLength includes the "hidden" bigits encoded in the exponent.
+  int BigitLength() const { return used_bigits_ + exponent_; }
+  Chunk& RawBigit(const int index);
+  const Chunk& RawBigit(const int index) const;
+  Chunk BigitOrZero(const int index) const;
+  void SubtractTimes(const Bignum& other, const int factor);
+
+  // The Bignum's value is value(bigits_buffer_) * 2^(exponent_ * kBigitSize),
+  // where the value of the buffer consists of the lower kBigitSize bits of
+  // the first used_bigits_ Chunks in bigits_buffer_, first chunk has lowest
+  // significant bits.
+  int16_t used_bigits_;
+  int16_t exponent_;
   Chunk bigits_buffer_[kBigitCapacity];
-  // A vector backed by bigits_buffer_. This way accesses to the array are
-  // checked for out-of-bounds errors.
-  Vector<Chunk> bigits_;
-  int used_digits_;
-  // The Bignum's value equals value(bigits_) * 2^(exponent_ * kBigitSize).
-  int exponent_;
-
-  DC_DISALLOW_COPY_AND_ASSIGN(Bignum);
+
+  DOUBLE_CONVERSION_DISALLOW_COPY_AND_ASSIGN(Bignum);
 };
 
 }  // namespace double_conversion