| 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/code_generator.h" // DartModulo. | 10 #include "vm/code_generator.h" // DartModulo. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 73 } |
| 74 | 74 |
| 75 | 75 |
| 76 static RawInteger* DoubleToInteger(double val, const char* error_msg) { | 76 static RawInteger* DoubleToInteger(double val, const char* error_msg) { |
| 77 if (isinf(val) || isnan(val)) { | 77 if (isinf(val) || isnan(val)) { |
| 78 const Array& args = Array::Handle(Array::New(1)); | 78 const Array& args = Array::Handle(Array::New(1)); |
| 79 args.SetAt(0, String::Handle(String::New(error_msg))); | 79 args.SetAt(0, String::Handle(String::New(error_msg))); |
| 80 Exceptions::ThrowByType(Exceptions::kUnsupported, args); | 80 Exceptions::ThrowByType(Exceptions::kUnsupported, args); |
| 81 } | 81 } |
| 82 const Bigint& big = Bigint::Handle(BigintOperations::NewFromDouble(val)); | 82 const Bigint& big = Bigint::Handle(BigintOperations::NewFromDouble(val)); |
| 83 if (BigintOperations::FitsIntoInt64(big)) { | 83 return big.AsValidInteger(); |
| 84 return Integer::New(BigintOperations::ToInt64(big)); | |
| 85 } else { | |
| 86 return big.raw(); | |
| 87 } | |
| 88 } | 84 } |
| 89 | 85 |
| 90 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { | 86 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { |
| 91 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); | 87 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); |
| 92 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); | 88 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); |
| 93 double right = right_object.value(); | 89 double right = right_object.value(); |
| 94 if (FLAG_trace_intrinsified_natives) { | 90 if (FLAG_trace_intrinsified_natives) { |
| 95 OS::Print("Double_trunc_div %f ~/ %f\n", left, right); | 91 OS::Print("Double_trunc_div %f ~/ %f\n", left, right); |
| 96 } | 92 } |
| 97 return DoubleToInteger(trunc(left / right), | 93 return DoubleToInteger(trunc(left / right), |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 286 |
| 291 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { | 287 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
| 292 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 288 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
| 293 // Include negative zero, infinity. | 289 // Include negative zero, infinity. |
| 294 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 290 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); |
| 295 } | 291 } |
| 296 | 292 |
| 297 // Add here only functions using/referring to old-style casts. | 293 // Add here only functions using/referring to old-style casts. |
| 298 | 294 |
| 299 } // namespace dart | 295 } // namespace dart |
| OLD | NEW |