Reviewers: Michael Starzinger,
Description:
Fix bug in bignum implementation.
R=mstarzin...@chromium.org
BUG=
Please review this at https://chromiumcodereview.appspot.com/13454019/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/bignum.h
M src/bignum.cc
M test/cctest/test-bignum-dtoa.cc
Index: src/bignum.cc
diff --git a/src/bignum.cc b/src/bignum.cc
index
9436322ed49b38080875e1a5eceef7861fbc3745..46e64faa313832a01b55fe474d0f6afe181fffdd
100644
--- a/src/bignum.cc
+++ b/src/bignum.cc
@@ -758,7 +758,6 @@ void Bignum::SubtractTimes(const Bignum& other, int
factor) {
Chunk difference = bigits_[i] - borrow;
bigits_[i] = difference & kBigitMask;
borrow = difference >> (kChunkSize - 1);
- ++i;
}
Clamp();
}
Index: src/bignum.h
diff --git a/src/bignum.h b/src/bignum.h
index
dcc4fa702aa0df5486555891a2b525958ec09ae6..af7626faa68de583143fc12be64fc6704fff79d3
100644
--- a/src/bignum.h
+++ b/src/bignum.h
@@ -133,9 +133,18 @@ class Bignum {
// The Bignum's value equals value(bigits_) * 2^(exponent_ * kBigitSize).
int exponent_;
+ friend class ExposeBignumSubtractTimesForTesting;
DISALLOW_COPY_AND_ASSIGN(Bignum);
};
+
+class ExposeBignumSubtractTimesForTesting {
+ public:
+ static void SubtractTimes(Bignum& a, Bignum& b, int factor) {
+ a.SubtractTimes(b, factor);
+ }
+};
+
} } // namespace v8::internal
#endif // V8_BIGNUM_H_
Index: test/cctest/test-bignum-dtoa.cc
diff --git a/test/cctest/test-bignum-dtoa.cc
b/test/cctest/test-bignum-dtoa.cc
index
a696ed8e3fc9acbf3c734f432f4b006a07012728..21d65c5bea46f4783cb3a4efab88b869e02b4093
100644
--- a/test/cctest/test-bignum-dtoa.cc
+++ b/test/cctest/test-bignum-dtoa.cc
@@ -29,6 +29,7 @@
#include "v8.h"
+#include "bignum.h"
#include "bignum-dtoa.h"
#include "cctest.h"
@@ -313,3 +314,16 @@ TEST(BignumDtoaGayPrecision) {
CHECK_EQ(current_test.representation, buffer.start());
}
}
+
+
+TEST(RegressBignumSubtractTimes) {
+ Bignum a, a_, b;
+
a.AssignHexString(CStrVector("10000000000000000000000000000000000000000000"));
+ b.AssignHexString(CStrVector("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"));
+ a_.AssignBignum(a);
+ // Test that a - 5*b + 5*b == a
+ ExposeBignumSubtractTimesForTesting::SubtractTimes(a, b, 5);
+ b.MultiplyByUInt32(5);
+ a.AddBignum(b);
+ CHECK(Bignum::Equal(a, a_));
+}
--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.