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

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

Issue 9113043: Implement Double.{toString, toStringAsExponential, toStringAsPrecision} (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert mintmaker changes. Created 8 years, 11 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 | runtime/lib/double.dart » ('j') | runtime/vm/double_conversion.h » ('J')
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 #include <math.h> 5 #include <math.h>
6 6
7 #include "vm/bootstrap_natives.h" 7 #include "vm/bootstrap_natives.h"
8 8
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/double_conversion.h" 10 #include "vm/double_conversion.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 arguments->SetReturn( 182 arguments->SetReturn(
183 Bigint::Handle(BigintOperations::NewFromDouble(result))); 183 Bigint::Handle(BigintOperations::NewFromDouble(result)));
184 } 184 }
185 } 185 }
186 186
187 187
188 DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) { 188 DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) {
189 const Double& arg = Double::CheckedHandle(arguments->At(0)); 189 const Double& arg = Double::CheckedHandle(arguments->At(0));
190 GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1)); 190 GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1));
191 double d = arg.value(); 191 double d = arg.value();
192 int fraction_digits_value = fraction_digits.Value(); 192 int fraction_digits_value = fraction_digits.Value();
Ivan Posva 2012/01/26 00:35:39 ditto from below!
floitsch 2012/01/27 12:51:07 Done.
193 String& result = String::Handle(); 193 String& result = String::Handle();
194 bool succeeded = DoubleToStringAsFixed(d, fraction_digits_value, result); 194 bool succeeded = DoubleToStringAsFixed(d, fraction_digits_value, result);
195 if (!succeeded) { 195 if (!succeeded) {
196 GrowableArray<const Object*> args; 196 GrowableArray<const Object*> args;
197 args.Add(&String::ZoneHandle(String::New( 197 args.Add(&String::ZoneHandle(String::New(
198 "Illegal arguments to double.toStringAsFixed"))); 198 "Illegal arguments to double.toStringAsFixed")));
199 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 199 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
200 } 200 }
201 arguments->SetReturn(result); 201 arguments->SetReturn(result);
202 } 202 }
203 203
204 204
205 DEFINE_NATIVE_ENTRY(Double_toStringAsExponential, 2) { 205 DEFINE_NATIVE_ENTRY(Double_toStringAsExponential, 2) {
206 UNIMPLEMENTED(); 206 const Double& arg = Double::CheckedHandle(arguments->At(0));
207 GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1));
208 double d = arg.value();
209 int fraction_digits_value = fraction_digits.Value();
Ivan Posva 2012/01/26 00:35:39 Potentially losing bits here!
floitsch 2012/01/27 12:51:07 The dart code already checked that the number was
210 String& result = String::Handle();
211 bool succeeded =
212 DoubleToStringAsExponential(d, fraction_digits_value, result);
213 if (!succeeded) {
214 GrowableArray<const Object*> args;
215 args.Add(&String::ZoneHandle(String::New(
216 "Illegal arguments to double.toStringAsExponential")));
217 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
218 }
219 arguments->SetReturn(result);
207 } 220 }
208 221
209 222
210 DEFINE_NATIVE_ENTRY(Double_toStringAsPrecision, 2) { 223 DEFINE_NATIVE_ENTRY(Double_toStringAsPrecision, 2) {
211 UNIMPLEMENTED(); 224 const Double& arg = Double::CheckedHandle(arguments->At(0));
225 GET_NATIVE_ARGUMENT(Smi, precision, arguments->At(1));
226 double d = arg.value();
227 int precision_value = precision.Value();
Ivan Posva 2012/01/26 00:35:39 ditto!
floitsch 2012/01/27 12:51:07 Done.
228 String& result = String::Handle();
229 bool succeeded = DoubleToStringAsPrecision(d, precision_value, result);
230 if (!succeeded) {
231 GrowableArray<const Object*> args;
232 args.Add(&String::ZoneHandle(String::New(
233 "Illegal arguments to double.toStringAsPrecision")));
234 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
235 }
236 arguments->SetReturn(result);
212 } 237 }
213 238
214 239
215 DEFINE_NATIVE_ENTRY(Double_isInfinite, 1) { 240 DEFINE_NATIVE_ENTRY(Double_isInfinite, 1) {
216 const Double& arg = Double::CheckedHandle(arguments->At(0)); 241 const Double& arg = Double::CheckedHandle(arguments->At(0));
217 if (isinf(arg.value())) { 242 if (isinf(arg.value())) {
218 arguments->SetReturn(Bool::Handle(Bool::True())); 243 arguments->SetReturn(Bool::Handle(Bool::True()));
219 } else { 244 } else {
220 arguments->SetReturn(Bool::Handle(Bool::False())); 245 arguments->SetReturn(Bool::Handle(Bool::False()));
221 } 246 }
(...skipping 17 matching lines...) Expand all
239 arguments->SetReturn(Bool::Handle(Bool::True())); 264 arguments->SetReturn(Bool::Handle(Bool::True()));
240 } else { 265 } else {
241 arguments->SetReturn(Bool::Handle(Bool::False())); 266 arguments->SetReturn(Bool::Handle(Bool::False()));
242 } 267 }
243 } 268 }
244 269
245 // Add here only functions using/referring to old-style casts. 270 // Add here only functions using/referring to old-style casts.
246 271
247 } // namespace dart 272 } // namespace dart
248 273
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/double.dart » ('j') | runtime/vm/double_conversion.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698