| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 num operator +(num other) { | 8 num operator +(num other) { |
| 9 return other.addFromInteger(this); | 9 return other.addFromInteger(this); |
| 10 } | 10 } |
| 11 num operator -(num other) { | 11 num operator -(num other) { |
| 12 return other.subFromInteger(this); | 12 return other.subFromInteger(this); |
| 13 } | 13 } |
| 14 num operator *(num other) { | 14 num operator *(num other) { |
| 15 return other.mulFromInteger(this); | 15 return other.mulFromInteger(this); |
| 16 } | 16 } |
| 17 num operator ~/(num other) { | 17 num operator ~/(num other) { |
| 18 if (other == 0) { | 18 if (other == 0) { |
| 19 throw const IntegerDivisionByZeroException(); | 19 throw const IntegerDivisionByZeroException(); |
| 20 } | 20 } |
| 21 return other.truncDivFromInteger(this); | 21 return other.truncDivFromInteger(this); |
| 22 } | 22 } |
| 23 num operator /(num other) { | 23 num operator /(num other) { |
| 24 return this.toDouble() / other.toDouble(); | 24 return this.toDouble() / other.toDouble(); |
| 25 } | 25 } |
| 26 num operator %(num other) { | 26 num operator %(num other) { |
| 27 if (other == 0) { | 27 if ((other is int) && (other == 0)) { |
| 28 throw const IntegerDivisionByZeroException(); | 28 throw const IntegerDivisionByZeroException(); |
| 29 } | 29 } |
| 30 return other.moduloFromInteger(this); | 30 return other.moduloFromInteger(this); |
| 31 } | 31 } |
| 32 int operator negate() { | 32 int operator negate() { |
| 33 return 0 - this; | 33 return 0 - this; |
| 34 } | 34 } |
| 35 int operator &(int other) { | 35 int operator &(int other) { |
| 36 return other.bitAndFromInteger(this); | 36 return other.bitAndFromInteger(this); |
| 37 } | 37 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 int truncate() { return this; } | 111 int truncate() { return this; } |
| 112 | 112 |
| 113 int toInt() { return this; } | 113 int toInt() { return this; } |
| 114 double toDouble() { return new Double.fromInteger(this); } | 114 double toDouble() { return new Double.fromInteger(this); } |
| 115 | 115 |
| 116 int pow(int exponent) { | 116 int pow(int exponent) { |
| 117 throw "IntegerImplementation.pow not implemented"; | 117 throw "IntegerImplementation.pow not implemented"; |
| 118 } | 118 } |
| 119 | 119 |
| 120 String toStringAsFixed(int fractionDigits) { | 120 String toStringAsFixed(int fractionDigits) { |
| 121 // Issue 460. |
| 121 throw "IntegerImplementation.toStringAsFixed not implemented"; | 122 throw "IntegerImplementation.toStringAsFixed not implemented"; |
| 122 } | 123 } |
| 123 String toStringAsExponential(int fractionDigits) { | 124 String toStringAsExponential(int fractionDigits) { |
| 125 // Issue 460. |
| 124 throw "IntegerImplementation.toStringAsExponential not implemented"; | 126 throw "IntegerImplementation.toStringAsExponential not implemented"; |
| 125 } | 127 } |
| 126 String toStringAsPrecision(int precision) { | 128 String toStringAsPrecision(int precision) { |
| 129 // Issue 460. |
| 127 throw "IntegerImplementation.toStringAsPrecision not implemented"; | 130 throw "IntegerImplementation.toStringAsPrecision not implemented"; |
| 128 } | 131 } |
| 129 String toRadixString(int radix) { | 132 String toRadixString(int radix) { |
| 130 final table = const ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", | 133 final table = const ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", |
| 131 "A", "B", "C", "D", "E", "F"]; | 134 "A", "B", "C", "D", "E", "F"]; |
| 132 if ((radix <= 1) || (radix > 16)) { | 135 if ((radix <= 1) || (radix > 16)) { |
| 133 throw "Bad radix: $radix"; | 136 throw "Bad radix: $radix"; |
| 134 } | 137 } |
| 135 final bool isNegative = this < 0; | 138 final bool isNegative = this < 0; |
| 136 var value = isNegative ? -this : this; | 139 var value = isNegative ? -this : this; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if (other < 0) { | 185 if (other < 0) { |
| 183 return -1; | 186 return -1; |
| 184 } else { | 187 } else { |
| 185 return 0; | 188 return 0; |
| 186 } | 189 } |
| 187 } | 190 } |
| 188 int shlFromInt(int other) { | 191 int shlFromInt(int other) { |
| 189 throw const OutOfMemoryException(); | 192 throw const OutOfMemoryException(); |
| 190 } | 193 } |
| 191 } | 194 } |
| OLD | NEW |