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 class _Double implements double { | 5 class _Double implements double { |
6 factory _Double.fromInteger(int value) | 6 factory _Double.fromInteger(int value) |
7 native "Double_doubleFromInteger"; | 7 native "Double_doubleFromInteger"; |
8 int get hashCode { | 8 int get hashCode { |
9 if (isNaN || isInfinite) return 0; | 9 if (isNaN || isInfinite) return 0; |
10 return toInt(); | 10 return toInt(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 119 } |
120 if (lowerLimit.isNaN) return lowerLimit; | 120 if (lowerLimit.isNaN) return lowerLimit; |
121 if (this.compareTo(lowerLimit) < 0) return lowerLimit; | 121 if (this.compareTo(lowerLimit) < 0) return lowerLimit; |
122 if (this.compareTo(upperLimit) > 0) return upperLimit; | 122 if (this.compareTo(upperLimit) > 0) return upperLimit; |
123 return this; | 123 return this; |
124 } | 124 } |
125 | 125 |
126 int toInt() native "Double_toInt"; | 126 int toInt() native "Double_toInt"; |
127 double toDouble() { return this; } | 127 double toDouble() { return this; } |
128 | 128 |
129 double pow(num exponent) { | |
130 if (exponent == 0) { | |
131 return 1.0; // ECMA-262 15.8.2.13 | |
132 } | |
133 if (exponent is! num) { | |
134 throw new ArgumentError(null); | |
135 } | |
136 double doubleExponent = exponent.toDouble(); | |
137 if (isNaN || exponent.isNaN) { | |
138 return double.NAN; | |
139 } | |
140 return _pow(doubleExponent); | |
141 } | |
142 double _pow(double exponent) native "Double_pow"; | |
143 | |
144 String toStringAsFixed(int fractionDigits) { | 129 String toStringAsFixed(int fractionDigits) { |
145 // See ECMAScript-262, 15.7.4.5 for details. | 130 // See ECMAScript-262, 15.7.4.5 for details. |
146 | 131 |
147 if (fractionDigits is! int) { | 132 if (fractionDigits is! int) { |
148 throw new ArgumentError(fractionDigits); | 133 throw new ArgumentError(fractionDigits); |
149 } | 134 } |
150 // Step 2. | 135 // Step 2. |
151 if (fractionDigits < 0 || fractionDigits > 20) { | 136 if (fractionDigits < 0 || fractionDigits > 20) { |
152 throw new RangeError(fractionDigits); | 137 throw new RangeError(fractionDigits); |
153 } | 138 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 return EQUAL; | 226 return EQUAL; |
242 } | 227 } |
243 } else if (isNaN) { | 228 } else if (isNaN) { |
244 return other.isNaN ? EQUAL : GREATER; | 229 return other.isNaN ? EQUAL : GREATER; |
245 } else { | 230 } else { |
246 // Other is NaN. | 231 // Other is NaN. |
247 return LESS; | 232 return LESS; |
248 } | 233 } |
249 } | 234 } |
250 } | 235 } |
OLD | NEW |