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

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 | tests/corelib/big_integer_vm_test.dart » ('j') | 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 DivideRemainder(a, b, &quotient, &remainder);
781 return modulo.raw(); 781 // Emulating code in Integer::ArithmeticOp (Euclidian modulo).
782 if (remainder.IsNegative()) {
783 if (b.IsNegative()) {
784 return BigintOperations::Subtract(remainder, b);
785 } else {
786 return BigintOperations::Add(remainder, b);
787 }
788 }
789 return remainder.raw();
782 } 790 }
783 791
784 792
785 RawBigint* BigintOperations::Remainder(const Bigint& a, const Bigint& b) { 793 RawBigint* BigintOperations::Remainder(const Bigint& a, const Bigint& b) {
786 Bigint& quotient = Bigint::Handle(); 794 Bigint& quotient = Bigint::Handle();
787 Bigint& remainder = Bigint::Handle(); 795 Bigint& remainder = Bigint::Handle();
788 DivideRemainder(a, b, &quotient, &remainder); 796 DivideRemainder(a, b, &quotient, &remainder);
789 return remainder.raw(); 797 return remainder.raw();
790 } 798 }
791 799
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 int BigintOperations::CountBits(Chunk digit) { 1656 int BigintOperations::CountBits(Chunk digit) {
1649 int result = 0; 1657 int result = 0;
1650 while (digit != 0) { 1658 while (digit != 0) {
1651 digit >>= 1; 1659 digit >>= 1;
1652 result++; 1660 result++;
1653 } 1661 }
1654 return result; 1662 return result;
1655 } 1663 }
1656 1664
1657 } // namespace dart 1665 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/big_integer_vm_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698