Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: runtime/lib/integers.dart

Issue 10692099: Fix int.compareTo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/corelib/compare_to_test.dart » ('j') | tests/corelib/compare_to_test.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 30 matching lines...) Expand all
41 } 41 }
42 int operator |(int other) { 42 int operator |(int other) {
43 return other.bitOrFromInteger(this); 43 return other.bitOrFromInteger(this);
44 } 44 }
45 int operator ^(int other) { 45 int operator ^(int other) {
46 return other.bitXorFromInteger(this); 46 return other.bitXorFromInteger(this);
47 } 47 }
48 num remainder(num other) { 48 num remainder(num other) {
49 return other.remainderFromInteger(this); 49 return other.remainderFromInteger(this);
50 } 50 }
51 int bitAndFromInteger(int other) native "Integer_bitAndFromInteger"; 51 int bitAndFromInteger(int other) native "Integer_bitAndFromInteger";
Lasse Reichstein Nielsen 2012/07/06 08:56:17 These are completely unspecified, even in the API
floitsch 2012/07/06 13:18:55 Yes. as discussed offline: we should maybe remove
52 int bitOrFromInteger(int other) native "Integer_bitOrFromInteger"; 52 int bitOrFromInteger(int other) native "Integer_bitOrFromInteger";
53 int bitXorFromInteger(int other) native "Integer_bitXorFromInteger"; 53 int bitXorFromInteger(int other) native "Integer_bitXorFromInteger";
54 int addFromInteger(int other) native "Integer_addFromInteger"; 54 int addFromInteger(int other) native "Integer_addFromInteger";
55 int subFromInteger(int other) native "Integer_subFromInteger"; 55 int subFromInteger(int other) native "Integer_subFromInteger";
56 int mulFromInteger(int other) native "Integer_mulFromInteger"; 56 int mulFromInteger(int other) native "Integer_mulFromInteger";
57 int truncDivFromInteger(int other) native "Integer_truncDivFromInteger"; 57 int truncDivFromInteger(int other) native "Integer_truncDivFromInteger";
58 int moduloFromInteger(int other) native "Integer_moduloFromInteger"; 58 int moduloFromInteger(int other) native "Integer_moduloFromInteger";
59 int remainderFromInteger(int other) { 59 int remainderFromInteger(int other) {
60 return other - (other ~/ this) * this; 60 return other - (other ~/ this) * this;
61 } 61 }
(...skipping 26 matching lines...) Expand all
88 bool equalToInteger(int other) native "Integer_equalToInteger"; 88 bool equalToInteger(int other) native "Integer_equalToInteger";
89 int abs() { 89 int abs() {
90 return this < 0 ? -this : this; 90 return this < 0 ? -this : this;
91 } 91 }
92 bool isEven() { return ((this & 1) === 0); } 92 bool isEven() { return ((this & 1) === 0); }
93 bool isOdd() { return !isEven(); } 93 bool isOdd() { return !isEven(); }
94 bool isNaN() { return false; } 94 bool isNaN() { return false; }
95 bool isNegative() { return this < 0; } 95 bool isNegative() { return this < 0; }
96 bool isInfinite() { return false; } 96 bool isInfinite() { return false; }
97 97
98 int compareTo(Comparable other) { 98 int compareTo(Comparable other) {
Lasse Reichstein Nielsen 2012/07/06 08:56:17 Argh. Why did we not define Comparable to be gener
floitsch 2012/07/06 13:18:55 Changing to num now, and adding generic type to co
99 final int EQUAL = 0, LESS = -1, GREATER = 1; 99 final int EQUAL = 0, LESS = -1, GREATER = 1;
100 if (other is double) {
101 // Let the double implementation deal with -0.0 and NaN.
102 return -other.compareTo(this.toDouble());
Lasse Reichstein Nielsen 2012/07/06 08:56:17 I think that's wrong. If this is, e.g., 1<<2000 (a
floitsch 2012/07/06 13:18:55 Done.
103 }
100 if (this < other) { 104 if (this < other) {
101 return LESS; 105 return LESS;
102 } else if (this > other) { 106 } else if (this > other) {
103 return GREATER; 107 return GREATER;
104 } else if (this == other) { 108 } else {
105 return EQUAL; 109 return EQUAL;
106 } else {
107 // Other is NaN.
108 return LESS;
109 } 110 }
110 } 111 }
111 112
112 int round() { return this; } 113 int round() { return this; }
113 int floor() { return this; } 114 int floor() { return this; }
114 int ceil() { return this; } 115 int ceil() { return this; }
115 int truncate() { return this; } 116 int truncate() { return this; }
116 117
117 int toInt() { return this; } 118 int toInt() { return this; }
118 double toDouble() { return new Double.fromInteger(this); } 119 double toDouble() { return new Double.fromInteger(this); }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 220 }
220 } 221 }
221 int shlFromInt(int other) { 222 int shlFromInt(int other) {
222 throw const OutOfMemoryException(); 223 throw const OutOfMemoryException();
223 } 224 }
224 225
225 int pow(int exponent) { 226 int pow(int exponent) {
226 throw "Bigint.pow not implemented"; 227 throw "Bigint.pow not implemented";
227 } 228 }
228 } 229 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/compare_to_test.dart » ('j') | tests/corelib/compare_to_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698