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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 Google Inc. All Rights Reserved. 1 // Copyright 2012 Google Inc. All Rights Reserved.
2 2
3 #include "vm/bigint_operations.h" 3 #include "vm/bigint_operations.h"
4 4
5 #include "platform/utils.h" 5 #include "platform/utils.h"
6 6
7 #include "vm/double_internals.h" 7 #include "vm/double_internals.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/zone.h" 10 #include "vm/zone.h"
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 RawBigint* BigintOperations::Divide(const Bigint& a, const Bigint& b) { 769 RawBigint* BigintOperations::Divide(const Bigint& a, const Bigint& b) {
770 Bigint& quotient = Bigint::Handle(); 770 Bigint& quotient = Bigint::Handle();
771 Bigint& remainder = Bigint::Handle(); 771 Bigint& remainder = Bigint::Handle();
772 DivideRemainder(a, b, &quotient, &remainder); 772 DivideRemainder(a, b, &quotient, &remainder);
773 return quotient.raw(); 773 return quotient.raw();
774 } 774 }
775 775
776 776
777 RawBigint* BigintOperations::Modulo(const Bigint& a, const Bigint& b) { 777 RawBigint* BigintOperations::Modulo(const Bigint& a, const Bigint& b) {
778 Bigint& quotient = Bigint::Handle(); 778 Bigint& quotient = Bigint::Handle();
779 Bigint& modulo = Bigint::Handle(); 779 Bigint& remainder = Bigint::Handle();
780 DivideRemainder(a, b, &quotient, &modulo); 780 Bigint& zero = Bigint::Handle(BigintOperations::Zero());
781 return modulo.raw(); 781 DivideRemainder(a, b, &quotient, &remainder);
782 // Emulating code in Integer::ArithmeticOp (Euclidian modulo).
783 if (BigintOperations::Compare(remainder, zero) == -1) {
floitsch 2012/10/19 08:18:54 if (remainder.isNegative())
srdjan 2012/10/19 14:56:02 Done.
784 if (BigintOperations::Compare(b, zero) == -1) {
floitsch 2012/10/19 08:18:54 if (b.isNegative())
srdjan 2012/10/19 14:56:02 Done.
785 return BigintOperations::Subtract(remainder, b);
786 } else {
787 return BigintOperations::Add(remainder, b);
788 }
789 }
790 return remainder.raw();
782 } 791 }
783 792
784 793
785 RawBigint* BigintOperations::Remainder(const Bigint& a, const Bigint& b) { 794 RawBigint* BigintOperations::Remainder(const Bigint& a, const Bigint& b) {
786 Bigint& quotient = Bigint::Handle(); 795 Bigint& quotient = Bigint::Handle();
787 Bigint& remainder = Bigint::Handle(); 796 Bigint& remainder = Bigint::Handle();
788 DivideRemainder(a, b, &quotient, &remainder); 797 DivideRemainder(a, b, &quotient, &remainder);
789 return remainder.raw(); 798 return remainder.raw();
790 } 799 }
791 800
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 int BigintOperations::CountBits(Chunk digit) { 1657 int BigintOperations::CountBits(Chunk digit) {
1649 int result = 0; 1658 int result = 0;
1650 while (digit != 0) { 1659 while (digit != 0) {
1651 digit >>= 1; 1660 digit >>= 1;
1652 result++; 1661 result++;
1653 } 1662 }
1654 return result; 1663 return result;
1655 } 1664 }
1656 1665
1657 } // namespace dart 1666 } // namespace dart
OLDNEW
« 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