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

Unified Diff: runtime/lib/double.cc

Issue 11801023: Cleanups. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/array_patch.dart ('k') | runtime/vm/ast.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/double.cc
===================================================================
--- runtime/lib/double.cc (revision 16730)
+++ runtime/lib/double.cc (working copy)
@@ -72,6 +72,21 @@
}
+static RawInteger* DoubleToInteger(double val, const char* error_msg) {
+ if (isinf(val) || isnan(val)) {
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, String::Handle(String::New(error_msg)));
+ Exceptions::ThrowByType(Exceptions::kUnsupported, args);
+ }
+ if ((Smi::kMinValue <= val) && (val <= Smi::kMaxValue)) {
+ return Smi::New(static_cast<intptr_t>(val));
+ } else if ((Mint::kMinValue <= val) && (val <= Mint::kMaxValue)) {
+ return Mint::New(static_cast<int64_t>(val));
+ } else {
+ return BigintOperations::NewFromDouble(val);
+ }
+}
+
DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) {
double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value();
GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1));
@@ -79,20 +94,8 @@
if (FLAG_trace_intrinsified_natives) {
OS::Print("Double_trunc_div %f ~/ %f\n", left, right);
}
- double result = trunc(left / right);
- if (isinf(result) || isnan(result)) {
- const Array& args = Array::Handle(Array::New(1));
- args.SetAt(0, String::Handle(String::New(
- "Result of truncating division is Infinity or NaN")));
- Exceptions::ThrowByType(Exceptions::kUnsupported, args);
- }
- if ((Smi::kMinValue <= result) && (result <= Smi::kMaxValue)) {
- return Smi::New(static_cast<intptr_t>(result));
- } else if ((Mint::kMinValue <= result) && (result <= Mint::kMaxValue)) {
- return Mint::New(static_cast<int64_t>(result));
- } else {
- return BigintOperations::NewFromDouble(result);
- }
+ return DoubleToInteger(trunc(left / right),
+ "Result of truncating division is Infinity or NaN");
}
@@ -201,19 +204,7 @@
DEFINE_NATIVE_ENTRY(Double_toInt, 1) {
const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0));
- if (isinf(arg.value()) || isnan(arg.value())) {
- const Array& args = Array::Handle(Array::New(1));
- args.SetAt(0, String::Handle(String::New("Infinity or NaN toInt")));
- Exceptions::ThrowByType(Exceptions::kUnsupported, args);
- }
- double result = trunc(arg.value());
- if ((Smi::kMinValue <= result) && (result <= Smi::kMaxValue)) {
- return Smi::New(static_cast<intptr_t>(result));
- } else if ((Mint::kMinValue <= result) && (result <= Mint::kMaxValue)) {
- return Mint::New(static_cast<int64_t>(result));
- } else {
- return BigintOperations::NewFromDouble(result);
- }
+ return DoubleToInteger(arg.value(), "Infinity or NaN toInt");
}
« no previous file with comments | « runtime/lib/array_patch.dart ('k') | runtime/vm/ast.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698