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

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

Issue 113833002: Add num.sign getter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed to return same type as the number (double for doubles, int for ints). Returns -0.0 for -0.0… Created 7 years 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
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 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 bool operator ==(other) { 85 bool operator ==(other) {
86 if (other is num) { 86 if (other is num) {
87 return other._equalToInteger(this); 87 return other._equalToInteger(this);
88 } 88 }
89 return false; 89 return false;
90 } 90 }
91 bool _equalToInteger(int other) native "Integer_equalToInteger"; 91 bool _equalToInteger(int other) native "Integer_equalToInteger";
92 int abs() { 92 int abs() {
93 return this < 0 ? -this : this; 93 return this < 0 ? -this : this;
94 } 94 }
95 int get sign {
96 return (this > 0) ? 1 : (this < 0) ? -1 : 0;
97 }
95 bool get isEven => ((this & 1) == 0); 98 bool get isEven => ((this & 1) == 0);
96 bool get isOdd => !isEven; 99 bool get isOdd => !isEven;
97 bool get isNaN => false; 100 bool get isNaN => false;
98 bool get isNegative => this < 0; 101 bool get isNegative => this < 0;
99 bool get isInfinite => false; 102 bool get isInfinite => false;
100 bool get isFinite => true; 103 bool get isFinite => true;
101 104
102 int toUnsigned(int width) { 105 int toUnsigned(int width) {
103 return this & ((1 << width) - 1); 106 return this & ((1 << width) - 1);
104 } 107 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } else { 337 } else {
335 return 0; 338 return 0;
336 } 339 }
337 } 340 }
338 int _shlFromInt(int other) native "Bigint_shlFromInt"; 341 int _shlFromInt(int other) native "Bigint_shlFromInt";
339 342
340 int pow(int exponent) { 343 int pow(int exponent) {
341 throw "Bigint.pow not implemented"; 344 throw "Bigint.pow not implemented";
342 } 345 }
343 } 346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698