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

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

Issue 2974633003: Option to truncate integers to 64 bits, part 1 (core VM changes) (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « no previous file | runtime/lib/integers.cc » ('j') | runtime/platform/utils.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 "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
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_truncate_ints_to_64_bits) {
83 // TODO(alexmarkov): decide on the double-to-integer conversion semantics
84 // in truncating mode.
regis 2017/07/07 20:10:29 Something to discuss with the API people. You coul
alexmarkov 2017/07/07 20:46:38 Acknowledged.
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
regis 2017/07/07 20:10:29 The convention is to use a capital letter and a pe
alexmarkov 2017/07/07 20:46:38 Done.
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
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
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/integers.cc » ('j') | runtime/platform/utils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698