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

Unified Diff: runtime/lib/integers.dart

Issue 14619027: Fix for issue 10534. Implement int.pow correctly. Note that int.pow is considerably slower than dou… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 | runtime/lib/math_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/integers.dart
===================================================================
--- runtime/lib/integers.dart (revision 22629)
+++ runtime/lib/integers.dart (working copy)
@@ -164,12 +164,17 @@
double toDouble() { return new _Double.fromInteger(this); }
int pow(int exponent) {
- double res = this.toDouble().pow(exponent);
- if (res.isInfinite) {
- // Use Bigint instead.
- throw "_IntegerImplementation.pow not implemented for large integers.";
+ // Exponentiation by squaring.
+ int base = this;
+ int result = 1;
+ while (exponent != 0) {
+ if ((exponent & 1) == 1) {
+ result *= base;
+ }
+ exponent >>= 1;
+ base *= base;
}
- return res.toInt();
+ return result;
}
String toStringAsFixed(int fractionDigits) {
« no previous file with comments | « no previous file | runtime/lib/math_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698