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

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

Issue 12180022: Fix Issue 8259: dart:math pow broken for large integers. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/pow_test.dart » ('j') | no next file with comments »
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 <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
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 Bigint& big = Bigint::Handle(BigintOperations::NewFromDouble(val));
83 return Smi::New(static_cast<intptr_t>(val)); 83 if (BigintOperations::FitsIntoSmi(big)) {
84 } else if ((Mint::kMinValue <= val) && (val <= Mint::kMaxValue)) { 84 return BigintOperations::ToSmi(big);
85 return Mint::New(static_cast<int64_t>(val)); 85 } else if (BigintOperations::FitsIntoMint(big)) {
86 return Mint::New(BigintOperations::ToMint(big));
86 } else { 87 } else {
87 return BigintOperations::NewFromDouble(val); 88 return big.raw();
88 } 89 }
89 } 90 }
90 91
91 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { 92 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) {
92 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); 93 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value();
93 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); 94 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1));
94 double right = right_object.value(); 95 double right = right_object.value();
95 if (FLAG_trace_intrinsified_natives) { 96 if (FLAG_trace_intrinsified_natives) {
96 OS::Print("Double_trunc_div %f ~/ %f\n", left, right); 97 OS::Print("Double_trunc_div %f ~/ %f\n", left, right);
97 } 98 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 323
323 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { 324 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) {
324 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); 325 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0));
325 // Include negative zero, infinity. 326 // Include negative zero, infinity.
326 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); 327 return Bool::Get(signbit(arg.value()) && !isnan(arg.value()));
327 } 328 }
328 329
329 // Add here only functions using/referring to old-style casts. 330 // Add here only functions using/referring to old-style casts.
330 331
331 } // namespace dart 332 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/pow_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698