Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(srdjan): fix limitations. | 5 // TODO(srdjan): fix limitations. |
| 6 // - shift amount must be a Smi. | 6 // - shift amount must be a Smi. |
| 7 class IntegerImplementation { | 7 class IntegerImplementation { |
| 8 factory IntegerImplementation._uninstantiable() { | 8 factory IntegerImplementation._uninstantiable() { |
| 9 throw const UnsupportedOperationException( | 9 throw const UnsupportedOperationException( |
| 10 "IntegerImplementation can only be allocated by the VM"); | 10 "IntegerImplementation can only be allocated by the VM"); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 } | 134 } |
| 135 String toStringAsPrecision(int precision) { | 135 String toStringAsPrecision(int precision) { |
| 136 return this.toDouble().toStringAsPrecision(precision); | 136 return this.toDouble().toStringAsPrecision(precision); |
| 137 } | 137 } |
| 138 String toRadixString(int radix) { | 138 String toRadixString(int radix) { |
| 139 final table = const ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", | 139 final table = const ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", |
| 140 "A", "B", "C", "D", "E", "F"]; | 140 "A", "B", "C", "D", "E", "F"]; |
| 141 if ((radix <= 1) || (radix > 16)) { | 141 if ((radix <= 1) || (radix > 16)) { |
| 142 throw "Bad radix: $radix"; | 142 throw "Bad radix: $radix"; |
| 143 } | 143 } |
| 144 final bool isNegative = this < 0; | 144 var value = this.isNegative() ? -this : this; |
|
Ivan Posva
2012/03/14 05:34:05
Please maintain the code as it was with a local va
zundel
2012/03/14 13:04:34
np, I'll revert this.
Background: the shadowing
| |
| 145 var value = isNegative ? -this : this; | |
| 146 List temp = new List(); | 145 List temp = new List(); |
| 147 while (value > 0) { | 146 while (value > 0) { |
| 148 var digit = value % radix; | 147 var digit = value % radix; |
| 149 value ~/= radix; | 148 value ~/= radix; |
| 150 temp.add(digit); | 149 temp.add(digit); |
| 151 } | 150 } |
| 152 if (temp.isEmpty()) { | 151 if (temp.isEmpty()) { |
| 153 return "0"; | 152 return "0"; |
| 154 } | 153 } |
| 155 StringBuffer buffer = new StringBuffer(); | 154 StringBuffer buffer = new StringBuffer(); |
| 156 if (isNegative) buffer.add("-"); | 155 if (this.isNegative()) buffer.add("-"); |
| 157 for (int i = temp.length - 1; i >= 0; i--) { | 156 for (int i = temp.length - 1; i >= 0; i--) { |
| 158 buffer.add(table[temp[i]]); | 157 buffer.add(table[temp[i]]); |
| 159 } | 158 } |
| 160 return buffer.toString(); | 159 return buffer.toString(); |
| 161 } | 160 } |
| 162 } | 161 } |
| 163 | 162 |
| 164 class Smi extends IntegerImplementation implements int { | 163 class Smi extends IntegerImplementation implements int { |
| 165 factory Smi._uninstantiable() { | 164 factory Smi._uninstantiable() { |
| 166 throw const UnsupportedOperationException( | 165 throw const UnsupportedOperationException( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 } | 218 } |
| 220 } | 219 } |
| 221 int shlFromInt(int other) { | 220 int shlFromInt(int other) { |
| 222 throw const OutOfMemoryException(); | 221 throw const OutOfMemoryException(); |
| 223 } | 222 } |
| 224 | 223 |
| 225 int pow(int exponent) { | 224 int pow(int exponent) { |
| 226 throw "Bigint.pow not implemented"; | 225 throw "Bigint.pow not implemented"; |
| 227 } | 226 } |
| 228 } | 227 } |
| OLD | NEW |