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

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

Issue 8430037: Fix issue: 5427703 (compareTo), fix parsing of -0.0. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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/vm/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 hashCode() { 8 int hashCode() {
9 try { 9 try {
10 return toInt(); 10 return toInt();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 bool isOdd() { 97 bool isOdd() {
98 // TODO(floitsch): find more efficient way to implement Double.isOdd. 98 // TODO(floitsch): find more efficient way to implement Double.isOdd.
99 return this % 2.0 == 1.0; 99 return this % 2.0 == 1.0;
100 } 100 }
101 bool isNegative() native "Double_isNegative"; 101 bool isNegative() native "Double_isNegative";
102 bool isInfinite() native "Double_isInfinite"; 102 bool isInfinite() native "Double_isInfinite";
103 bool isNaN() native "Double_isNaN"; 103 bool isNaN() native "Double_isNaN";
104 104
105 double abs() { 105 double abs() {
106 // Handle negative 0.0.
107 if (this == 0.0) return 0.0;
106 return this < 0.0 ? -this : this; 108 return this < 0.0 ? -this : this;
107 } 109 }
108 110
109 double round() native "Double_round"; 111 double round() native "Double_round";
110 double floor() native "Double_floor"; 112 double floor() native "Double_floor";
111 double ceil () native "Double_ceil"; 113 double ceil () native "Double_ceil";
112 double truncate() native "Double_truncate"; 114 double truncate() native "Double_truncate";
113 int toInt() native "Double_toInt"; 115 int toInt() native "Double_toInt";
114 double toDouble() { return this; } 116 double toDouble() { return this; }
115 117
(...skipping 16 matching lines...) Expand all
132 134
133 // Step 4. 135 // Step 4.
134 if (x.isNaN()) { 136 if (x.isNaN()) {
135 return "NaN"; 137 return "NaN";
136 } 138 }
137 139
138 // Step 5. 140 // Step 5.
139 String s = ""; 141 String s = "";
140 142
141 // Step 6. 143 // Step 6.
142 if (x.isNegative()) { 144 if (x.isNegative() && x != 0.0) {
143 s = "-"; 145 s = "-";
144 x = -x; 146 x = -x;
145 } 147 }
146 148
147 // Step 7. 149 // Step 7.
148 String m; 150 String m;
149 if (x > 10e21) { 151 if (x > 10e21) {
150 m = x.toString(); 152 m = x.toString();
151 } else { 153 } else {
152 // Step 8. 154 // Step 8.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 187 }
186 String toStringAsExponential(int fractionDigits) { 188 String toStringAsExponential(int fractionDigits) {
187 throw "Double.toStringAsExponential unimplemented."; 189 throw "Double.toStringAsExponential unimplemented.";
188 } 190 }
189 String toStringAsPrecision(int precision) { 191 String toStringAsPrecision(int precision) {
190 throw "Double.toStringAsPrecision unimplemented."; 192 throw "Double.toStringAsPrecision unimplemented.";
191 } 193 }
192 String toRadixString(int radix) { 194 String toRadixString(int radix) {
193 throw "Double.toRadixString unimplemented."; 195 throw "Double.toRadixString unimplemented.";
194 } 196 }
197
198 // Order is: NaN > Infinity > ... > 0.0 > -0.0 > ... > -Infinity.
195 int compareTo(Comparable other) { 199 int compareTo(Comparable other) {
196 if (this == other) return 0; 200 final int EQUAL = 0, LESS = -1, GREATER = 1;
197 if (this < other) return -1; 201 if (this < other) {
198 return 1; 202 return LESS;
203 } else if (this > other) {
204 return GREATER;
205 } else if (this == other) {
206 if (this == 0.0) {
207 bool thisIsNegative = isNegative();
208 bool otherIsNegative = other.isNegative();
209 if (thisIsNegative == otherIsNegative) {
210 return EQUAL;
211 }
212 return thisIsNegative ? LESS : GREATER;
213 } else {
214 return EQUAL;
215 }
216 } else if (isNaN()) {
217 return other.isNaN() ? EQUAL : GREATER;
218 } else {
219 // Other is NaN.
220 return LESS;
221 }
199 } 222 }
200 } 223 }
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698