OLD | NEW |
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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); |
| 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(); |
| 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 Loading... |
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 |
OLD | NEW |