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 new UnsupportedError( | 9 throw new UnsupportedError( |
10 "_IntegerImplementation can only be allocated by the VM"); | 10 "_IntegerImplementation can only be allocated by the VM"); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 throw new ArgumentError(radix); | 161 throw new ArgumentError(radix); |
162 } | 162 } |
163 final bool isNegative = this < 0; | 163 final bool isNegative = this < 0; |
164 var value = isNegative ? -this : this; | 164 var value = isNegative ? -this : this; |
165 List temp = new List(); | 165 List temp = new List(); |
166 while (value > 0) { | 166 while (value > 0) { |
167 var digit = value % radix; | 167 var digit = value % radix; |
168 value ~/= radix; | 168 value ~/= radix; |
169 temp.add(digit); | 169 temp.add(digit); |
170 } | 170 } |
171 if (temp.isEmpty()) { | 171 if (temp.isEmpty) { |
172 return "0"; | 172 return "0"; |
173 } | 173 } |
174 StringBuffer buffer = new StringBuffer(); | 174 StringBuffer buffer = new StringBuffer(); |
175 if (isNegative) buffer.add("-"); | 175 if (isNegative) buffer.add("-"); |
176 for (int i = temp.length - 1; i >= 0; i--) { | 176 for (int i = temp.length - 1; i >= 0; i--) { |
177 buffer.add(table[temp[i]]); | 177 buffer.add(table[temp[i]]); |
178 } | 178 } |
179 return buffer.toString(); | 179 return buffer.toString(); |
180 } | 180 } |
181 } | 181 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 238 } |
239 } | 239 } |
240 int _shlFromInt(int other) { | 240 int _shlFromInt(int other) { |
241 throw const OutOfMemoryError(); | 241 throw const OutOfMemoryError(); |
242 } | 242 } |
243 | 243 |
244 int pow(int exponent) { | 244 int pow(int exponent) { |
245 throw "Bigint.pow not implemented"; | 245 throw "Bigint.pow not implemented"; |
246 } | 246 } |
247 } | 247 } |
OLD | NEW |