Chromium Code Reviews| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 return Double::New(left / right); | 72 return Double::New(left / right); |
| 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 if ((Smi::kMinValue <= val) && (val <= Smi::kMaxValue)) { | 82 const int64_t int64_val = static_cast<int64_t>(val); |
| 83 return Smi::New(static_cast<intptr_t>(val)); | 83 // Check if overflow in double-to-int. |
| 84 } else if ((Mint::kMinValue <= val) && (val <= Mint::kMaxValue)) { | 84 if ((int64_val == static_cast<int64_t>(0x8000000000000000LL)) && |
|
Vyacheslav Egorov (Google)
2013/02/05 00:34:36
I don't think we can do this.
If a truncated doub
| |
| 85 return Mint::New(static_cast<int64_t>(val)); | 85 ((val < -2.0) || (val > 0.0))) { |
| 86 return BigintOperations::NewFromDouble(val); | |
| 87 } else if ((Smi::kMinValue <= int64_val) && (int64_val <= Smi::kMaxValue)) { | |
| 88 return Smi::New(static_cast<intptr_t>(int64_val)); | |
| 86 } else { | 89 } else { |
| 87 return BigintOperations::NewFromDouble(val); | 90 ASSERT((Mint::kMinValue <= int64_val) && (int64_val <= Mint::kMaxValue)); |
| 91 return Mint::New(int64_val); | |
| 88 } | 92 } |
| 89 } | 93 } |
| 90 | 94 |
| 91 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { | 95 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { |
| 92 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); | 96 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); |
| 93 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); | 97 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); |
| 94 double right = right_object.value(); | 98 double right = right_object.value(); |
| 95 if (FLAG_trace_intrinsified_natives) { | 99 if (FLAG_trace_intrinsified_natives) { |
| 96 OS::Print("Double_trunc_div %f ~/ %f\n", left, right); | 100 OS::Print("Double_trunc_div %f ~/ %f\n", left, right); |
| 97 } | 101 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 | 326 |
| 323 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { | 327 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
| 324 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 328 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
| 325 // Include negative zero, infinity. | 329 // Include negative zero, infinity. |
| 326 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 330 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); |
| 327 } | 331 } |
| 328 | 332 |
| 329 // Add here only functions using/referring to old-style casts. | 333 // Add here only functions using/referring to old-style casts. |
| 330 | 334 |
| 331 } // namespace dart | 335 } // namespace dart |
| OLD | NEW |