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 abstract class _IntegerImplementation { | 5 abstract class _IntegerImplementation { |
6 // The Dart class _Bigint extending _IntegerImplementation requires a | 6 // The Dart class _Bigint extending _IntegerImplementation requires a |
7 // default constructor. | 7 // default constructor. |
8 | 8 |
9 Type get runtimeType => int; | 9 Type get runtimeType => int; |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 if (result != null) return result; | 85 if (result != null) return result; |
86 return other._toBigint()._shlFromInt(this); | 86 return other._toBigint()._shlFromInt(this); |
87 } | 87 } |
88 bool operator <(num other) { | 88 bool operator <(num other) { |
89 return other > this; | 89 return other > this; |
90 } | 90 } |
91 bool operator >(num other) { | 91 bool operator >(num other) { |
92 return other._greaterThanFromInteger(this); | 92 return other._greaterThanFromInteger(this); |
93 } | 93 } |
94 bool operator >=(num other) { | 94 bool operator >=(num other) { |
95 return (this == other) || (this > other); | 95 return (this == other) || (this > other); |
96 } | 96 } |
97 bool operator <=(num other) { | 97 bool operator <=(num other) { |
98 return (this == other) || (this < other); | 98 return (this == other) || (this < other); |
99 } | 99 } |
100 bool _greaterThanFromInteger(int other) | 100 bool _greaterThanFromInteger(int other) |
101 native "Integer_greaterThanFromInteger"; | 101 native "Integer_greaterThanFromInteger"; |
| 102 bool _greaterThanFromPixels(pixels other) { |
| 103 return other._value > (this << _Pixels._SCALING_BITS); |
| 104 } |
102 bool operator ==(other) { | 105 bool operator ==(other) { |
103 if (other is num) { | 106 if (other is num) { |
104 return other._equalToInteger(this); | 107 return other._equalToInteger(this); |
105 } | 108 } |
106 return false; | 109 return false; |
107 } | 110 } |
108 bool _equalToInteger(int other) native "Integer_equalToInteger"; | 111 bool _equalToInteger(int other) native "Integer_equalToInteger"; |
| 112 bool _equalToPixels(pixels other) { |
| 113 return (this << _Pixels._SCALING_BITS) == other._value; |
| 114 } |
109 int abs() { | 115 int abs() { |
110 return this < 0 ? -this : this; | 116 return this < 0 ? -this : this; |
111 } | 117 } |
112 int get sign { | 118 int get sign { |
113 return (this > 0) ? 1 : (this < 0) ? -1 : 0; | 119 return (this > 0) ? 1 : (this < 0) ? -1 : 0; |
114 } | 120 } |
115 bool get isEven => ((this & 1) == 0); | 121 bool get isEven => ((this & 1) == 0); |
116 bool get isOdd => !isEven; | 122 bool get isOdd => !isEven; |
117 bool get isNaN => false; | 123 bool get isNaN => false; |
118 bool get isNegative => this < 0; | 124 bool get isNegative => this < 0; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 199 } |
194 if (lowerLimit.isNaN) return lowerLimit; | 200 if (lowerLimit.isNaN) return lowerLimit; |
195 // Note that we don't need to care for -0.0 for the lower limit. | 201 // Note that we don't need to care for -0.0 for the lower limit. |
196 if (this < lowerLimit) return lowerLimit; | 202 if (this < lowerLimit) return lowerLimit; |
197 if (this.compareTo(upperLimit) > 0) return upperLimit; | 203 if (this.compareTo(upperLimit) > 0) return upperLimit; |
198 return this; | 204 return this; |
199 } | 205 } |
200 | 206 |
201 int toInt() { return this; } | 207 int toInt() { return this; } |
202 double toDouble() { return new _Double.fromInteger(this); } | 208 double toDouble() { return new _Double.fromInteger(this); } |
| 209 pixels toPixels() { return new _Pixels.fromInteger(this); } |
203 _Bigint _toBigint() { return new _Bigint._fromInt(this); } | 210 _Bigint _toBigint() { return new _Bigint._fromInt(this); } |
204 num _toBigintOrDouble() { return _toBigint(); } | 211 num _toBigintIfInteger() { return _toBigint(); } |
| 212 num _toDoubleOrPixels() { return new _Pixels.fromInteger(this); } |
205 | 213 |
206 String toStringAsFixed(int fractionDigits) { | 214 String toStringAsFixed(int fractionDigits) { |
207 return this.toDouble().toStringAsFixed(fractionDigits); | 215 return this.toDouble().toStringAsFixed(fractionDigits); |
208 } | 216 } |
209 String toStringAsExponential([int fractionDigits]) { | 217 String toStringAsExponential([int fractionDigits]) { |
210 return this.toDouble().toStringAsExponential(fractionDigits); | 218 return this.toDouble().toStringAsExponential(fractionDigits); |
211 } | 219 } |
212 String toStringAsPrecision(int precision) { | 220 String toStringAsPrecision(int precision) { |
213 return this.toDouble().toStringAsPrecision(precision); | 221 return this.toDouble().toStringAsPrecision(precision); |
214 } | 222 } |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 // Shift by mint exceeds range that can be handled by the VM. | 626 // Shift by mint exceeds range that can be handled by the VM. |
619 int _shrFromInt(int other) { | 627 int _shrFromInt(int other) { |
620 if (other < 0) { | 628 if (other < 0) { |
621 return -1; | 629 return -1; |
622 } else { | 630 } else { |
623 return 0; | 631 return 0; |
624 } | 632 } |
625 } | 633 } |
626 int _shlFromInt(int other) native "Mint_shlFromInt"; | 634 int _shlFromInt(int other) native "Mint_shlFromInt"; |
627 } | 635 } |
OLD | NEW |