Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1142)

Unified Diff: runtime/vm/bigint_operations.cc

Issue 11192074: Fix bigint modulo operation. Fixes bug 6056 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/bigint_operations.cc
===================================================================
--- runtime/vm/bigint_operations.cc (revision 13805)
+++ runtime/vm/bigint_operations.cc (working copy)
@@ -776,9 +776,18 @@
RawBigint* BigintOperations::Modulo(const Bigint& a, const Bigint& b) {
Bigint& quotient = Bigint::Handle();
- Bigint& modulo = Bigint::Handle();
- DivideRemainder(a, b, &quotient, &modulo);
- return modulo.raw();
+ Bigint& remainder = Bigint::Handle();
+ Bigint& zero = Bigint::Handle(BigintOperations::Zero());
+ DivideRemainder(a, b, &quotient, &remainder);
+ // Emulating code in Integer::ArithmeticOp (Euclidian modulo).
+ if (BigintOperations::Compare(remainder, zero) == -1) {
floitsch 2012/10/19 08:18:54 if (remainder.isNegative())
srdjan 2012/10/19 14:56:02 Done.
+ if (BigintOperations::Compare(b, zero) == -1) {
floitsch 2012/10/19 08:18:54 if (b.isNegative())
srdjan 2012/10/19 14:56:02 Done.
+ return BigintOperations::Subtract(remainder, b);
+ } else {
+ return BigintOperations::Add(remainder, b);
+ }
+ }
+ return remainder.raw();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698