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

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

Issue 9565035: Some fixes to Math.pow. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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/co19/co19-runtime.status » ('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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 double round() native "Double_round"; 107 double round() native "Double_round";
108 double floor() native "Double_floor"; 108 double floor() native "Double_floor";
109 double ceil () native "Double_ceil"; 109 double ceil () native "Double_ceil";
110 double truncate() native "Double_truncate"; 110 double truncate() native "Double_truncate";
111 int toInt() native "Double_toInt"; 111 int toInt() native "Double_toInt";
112 double toDouble() { return this; } 112 double toDouble() { return this; }
113 113
114 double pow(num exponent) { 114 double pow(num exponent) {
115 return _pow(exponent.toDouble()); 115 if (exponent == 0) {
116 return 1.0; // ECMA-262 15.8.2.13
ngeoffray 2012/03/02 07:55:47 Wouldn't it be better to point to Dart spec instea
srdjan 2012/03/02 17:55:37 Good point. There is no Dart library spec for "pow
117 }
118 // Throw NullPointerException if exponent is null.
119 double doubleExponent = exponent.toDouble();
120 if (isNaN() || exponent.isNaN()) {
121 return double.NAN;
122 }
123 return _pow(doubleExponent);
116 } 124 }
117 double _pow(double exponent) native "Double_pow"; 125 double _pow(double exponent) native "Double_pow";
118 126
119 String toStringAsFixed(int fractionDigits) { 127 String toStringAsFixed(int fractionDigits) {
120 // See ECMAScript-262, 15.7.4.5 for details. 128 // See ECMAScript-262, 15.7.4.5 for details.
121 129
122 // Step 2. 130 // Step 2.
123 if (fractionDigits < 0 || fractionDigits > 20) { 131 if (fractionDigits < 0 || fractionDigits > 20) {
124 // TODO(antonm): should be proper RangeError or Dart counterpart. 132 // TODO(antonm): should be proper RangeError or Dart counterpart.
125 throw "Range error"; 133 throw "Range error";
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return EQUAL; 222 return EQUAL;
215 } 223 }
216 } else if (isNaN()) { 224 } else if (isNaN()) {
217 return other.isNaN() ? EQUAL : GREATER; 225 return other.isNaN() ? EQUAL : GREATER;
218 } else { 226 } else {
219 // Other is NaN. 227 // Other is NaN.
220 return LESS; 228 return LESS;
221 } 229 }
222 } 230 }
223 } 231 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698