Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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, "ient, &remainder); | 772 DivideRemainder(a, b, "ient, &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, "ient, &modulo); | 780 Bigint& zero = Bigint::Handle(BigintOperations::Zero()); |
| 781 return modulo.raw(); | 781 DivideRemainder(a, b, "ient, &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, "ient, &remainder); | 797 DivideRemainder(a, b, "ient, &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 Loading... | |
| 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 |
| OLD | NEW |