Title: [149609] trunk/Source/WTF
Revision
149609
Author
[email protected]
Date
2013-05-06 10:49:52 -0700 (Mon, 06 May 2013)

Log Message

Cherry-pick fixes to bignum from upstream
https://bugs.webkit.org/show_bug.cgi?id=115658

Patch by Cosmin Truta <[email protected]> on 2013-05-06
Reviewed by Darin Adler.

Cherry-picked the following change lists:

Fix bug in bignum implementation
http://codereview.chromium.org/13454019

Make VS2005 project files compile without errors
http://codereview.chromium.org/6286135

* wtf/dtoa/bignum.cc:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (149608 => 149609)


--- trunk/Source/WTF/ChangeLog	2013-05-06 17:48:24 UTC (rev 149608)
+++ trunk/Source/WTF/ChangeLog	2013-05-06 17:49:52 UTC (rev 149609)
@@ -1,3 +1,20 @@
+2013-05-06  Cosmin Truta  <[email protected]>
+
+        Cherry-pick fixes to bignum from upstream
+        https://bugs.webkit.org/show_bug.cgi?id=115658
+
+        Reviewed by Darin Adler.
+
+        Cherry-picked the following change lists:
+
+        Fix bug in bignum implementation
+        http://codereview.chromium.org/13454019
+
+        Make VS2005 project files compile without errors
+        http://codereview.chromium.org/6286135
+
+        * wtf/dtoa/bignum.cc:
+
 2013-05-06  Mikhail Pozdnyakov  <[email protected]>
 
         Change HashTraits<RefPtr<P> >::PassOutType to PassRefPtr for better performance

Modified: trunk/Source/WTF/wtf/dtoa/bignum.cc (149608 => 149609)


--- trunk/Source/WTF/wtf/dtoa/bignum.cc	2013-05-06 17:48:24 UTC (rev 149608)
+++ trunk/Source/WTF/wtf/dtoa/bignum.cc	2013-05-06 17:49:52 UTC (rev 149609)
@@ -68,7 +68,7 @@
         int needed_bigits = kUInt64Size / kBigitSize + 1;
         EnsureCapacity(needed_bigits);
         for (int i = 0; i < needed_bigits; ++i) {
-            bigits_[i] = (uint32_t)value & kBigitMask;
+            bigits_[i] = static_cast<Chunk>(value & kBigitMask);
             value = value >> kBigitSize;
         }
         used_digits_ = needed_bigits;
@@ -267,7 +267,7 @@
         }
         while (carry != 0) {
             EnsureCapacity(used_digits_ + 1);
-            bigits_[used_digits_] = (uint32_t)carry & kBigitMask;
+            bigits_[used_digits_] = static_cast<Chunk>(carry & kBigitMask);
             used_digits_++;
             carry >>= kBigitSize;
         }
@@ -288,13 +288,13 @@
             uint64_t product_low = low * bigits_[i];
             uint64_t product_high = high * bigits_[i];
             uint64_t tmp = (carry & kBigitMask) + product_low;
-            bigits_[i] = (uint32_t)tmp & kBigitMask;
+            bigits_[i] = static_cast<Chunk>(tmp & kBigitMask);
             carry = (carry >> kBigitSize) + (tmp >> kBigitSize) +
             (product_high << (32 - kBigitSize));
         }
         while (carry != 0) {
             EnsureCapacity(used_digits_ + 1);
-            bigits_[used_digits_] = (uint32_t)carry & kBigitMask;
+            bigits_[used_digits_] = static_cast<Chunk>(carry & kBigitMask);
             used_digits_++;
             carry >>= kBigitSize;
         }
@@ -737,6 +737,13 @@
     
     
     void Bignum::SubtractTimes(const Bignum& other, int factor) {
+#ifndef NDEBUG
+        Bignum a, b;
+        a.AssignBignum(*this);
+        b.AssignBignum(other);
+        b.MultiplyByUInt32(factor);
+        a.SubtractBignum(b);
+#endif
         ASSERT(exponent_ <= other.exponent_);
         if (factor < 3) {
             for (int i = 0; i < factor; ++i) {
@@ -749,7 +756,8 @@
         for (int i = 0; i < other.used_digits_; ++i) {
             DoubleChunk product = static_cast<DoubleChunk>(factor) * other.bigits_[i];
             DoubleChunk remove = borrow + product;
-            Chunk difference = bigits_[i + exponent_diff] - ((uint32_t)remove & kBigitMask);
+            Chunk difference =
+                bigits_[i + exponent_diff] - static_cast<Chunk>(remove & kBigitMask);
             bigits_[i + exponent_diff] = difference & kBigitMask;
             borrow = static_cast<Chunk>((difference >> (kChunkSize - 1)) +
                                         (remove >> kBigitSize));
@@ -759,9 +767,9 @@
             Chunk difference = bigits_[i] - borrow;
             bigits_[i] = difference & kBigitMask;
             borrow = difference >> (kChunkSize - 1);
-            ++i;
         }
         Clamp();
+        ASSERT(Bignum::Equal(a, *this));
     }
     
     
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to