| 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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "platform/math.h" | 7 #include "platform/math.h" |
| 8 | 8 |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/double_conversion.h" | 10 #include "vm/double_conversion.h" |
| (...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 (FLAG_limit_ints_to_64_bits) { |
| 83 // TODO(alexmarkov): decide on the double-to-integer conversion semantics |
| 84 // in truncating mode. |
| 85 int64_t ival = 0; |
| 86 if (val <= static_cast<double>(kMinInt64)) { |
| 87 ival = kMinInt64; |
| 88 } else if (val >= static_cast<double>(kMaxInt64)) { |
| 89 ival = kMaxInt64; |
| 90 } else { // Representable in int64_t. |
| 91 ival = static_cast<int64_t>(val); |
| 92 } |
| 93 return Integer::New(ival); |
| 94 } |
| 82 if ((-1.0 < val) && (val < 1.0)) { | 95 if ((-1.0 < val) && (val < 1.0)) { |
| 83 return Smi::New(0); | 96 return Smi::New(0); |
| 84 } | 97 } |
| 85 DoubleInternals internals = DoubleInternals(val); | 98 DoubleInternals internals = DoubleInternals(val); |
| 86 ASSERT(!internals.IsSpecial()); // Only Infinity and NaN are special. | 99 ASSERT(!internals.IsSpecial()); // Only Infinity and NaN are special. |
| 87 uint64_t significand = internals.Significand(); | 100 uint64_t significand = internals.Significand(); |
| 88 intptr_t exponent = internals.Exponent(); | 101 intptr_t exponent = internals.Exponent(); |
| 89 if (exponent <= 0) { | 102 if (exponent <= 0) { |
| 90 significand >>= -exponent; | 103 significand >>= -exponent; |
| 91 exponent = 0; | 104 exponent = 0; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 DEFINE_NATIVE_ENTRY(Double_flipSignBit, 1) { | 322 DEFINE_NATIVE_ENTRY(Double_flipSignBit, 1) { |
| 310 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 323 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
| 311 const double in_val = arg.value(); | 324 const double in_val = arg.value(); |
| 312 const int64_t bits = bit_cast<int64_t, double>(in_val) ^ kSignBitDouble; | 325 const int64_t bits = bit_cast<int64_t, double>(in_val) ^ kSignBitDouble; |
| 313 return Double::New(bit_cast<double, int64_t>(bits)); | 326 return Double::New(bit_cast<double, int64_t>(bits)); |
| 314 } | 327 } |
| 315 | 328 |
| 316 // Add here only functions using/referring to old-style casts. | 329 // Add here only functions using/referring to old-style casts. |
| 317 | 330 |
| 318 } // namespace dart | 331 } // namespace dart |
| OLD | NEW |