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

Side by Side Diff: runtime/lib/double.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
« no previous file with comments | « no previous file | runtime/lib/integers.dart » ('j') | sdk/lib/_internal/lib/js_number.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 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 8
9 Type get runtimeType => double; 9 Type get runtimeType => double;
10 10
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 bool get isInfinite native "Double_getIsInfinite"; 97 bool get isInfinite native "Double_getIsInfinite";
98 bool get isNaN native "Double_getIsNaN"; 98 bool get isNaN native "Double_getIsNaN";
99 bool get isFinite => !isInfinite && !isNaN; // Can be optimized. 99 bool get isFinite => !isInfinite && !isNaN; // Can be optimized.
100 100
101 double abs() { 101 double abs() {
102 // Handle negative 0.0. 102 // Handle negative 0.0.
103 if (this == 0.0) return 0.0; 103 if (this == 0.0) return 0.0;
104 return this < 0.0 ? -this : this; 104 return this < 0.0 ? -this : this;
105 } 105 }
106 106
107 double get sign {
108 if (this > 0.0) return 1.0;
109 if (this < 0.0) return -1.0;
110 return this; // +/-0.0 or NaN.
111 }
112
107 int round() => roundToDouble().toInt(); 113 int round() => roundToDouble().toInt();
108 int floor() => floorToDouble().toInt(); 114 int floor() => floorToDouble().toInt();
109 int ceil () => ceilToDouble().toInt(); 115 int ceil () => ceilToDouble().toInt();
110 int truncate() => truncateToDouble().toInt(); 116 int truncate() => truncateToDouble().toInt();
111 117
112 double roundToDouble() native "Double_round"; 118 double roundToDouble() native "Double_round";
113 double floorToDouble() native "Double_floor"; 119 double floorToDouble() native "Double_floor";
114 double ceilToDouble() native "Double_ceil"; 120 double ceilToDouble() native "Double_ceil";
115 double truncateToDouble() native "Double_truncate"; 121 double truncateToDouble() native "Double_truncate";
116 122
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 return EQUAL; 236 return EQUAL;
231 } 237 }
232 } else if (isNaN) { 238 } else if (isNaN) {
233 return other.isNaN ? EQUAL : GREATER; 239 return other.isNaN ? EQUAL : GREATER;
234 } else { 240 } else {
235 // Other is NaN. 241 // Other is NaN.
236 return LESS; 242 return LESS;
237 } 243 }
238 } 244 }
239 } 245 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/integers.dart » ('j') | sdk/lib/_internal/lib/js_number.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698