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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/array_patch.dart ('k') | runtime/vm/ast.h » ('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/double_conversion.h" 10 #include "vm/double_conversion.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); 65 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value();
66 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); 66 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1));
67 double right = right_object.value(); 67 double right = right_object.value();
68 if (FLAG_trace_intrinsified_natives) { 68 if (FLAG_trace_intrinsified_natives) {
69 OS::Print("Double_div %f / %f\n", left, right); 69 OS::Print("Double_div %f / %f\n", left, right);
70 } 70 }
71 return Double::New(left / right); 71 return Double::New(left / right);
72 } 72 }
73 73
74 74
75 static RawInteger* DoubleToInteger(double val, const char* error_msg) {
76 if (isinf(val) || isnan(val)) {
77 const Array& args = Array::Handle(Array::New(1));
78 args.SetAt(0, String::Handle(String::New(error_msg)));
79 Exceptions::ThrowByType(Exceptions::kUnsupported, args);
80 }
81 if ((Smi::kMinValue <= val) && (val <= Smi::kMaxValue)) {
82 return Smi::New(static_cast<intptr_t>(val));
83 } else if ((Mint::kMinValue <= val) && (val <= Mint::kMaxValue)) {
84 return Mint::New(static_cast<int64_t>(val));
85 } else {
86 return BigintOperations::NewFromDouble(val);
87 }
88 }
89
75 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { 90 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) {
76 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); 91 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value();
77 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); 92 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1));
78 double right = right_object.value(); 93 double right = right_object.value();
79 if (FLAG_trace_intrinsified_natives) { 94 if (FLAG_trace_intrinsified_natives) {
80 OS::Print("Double_trunc_div %f ~/ %f\n", left, right); 95 OS::Print("Double_trunc_div %f ~/ %f\n", left, right);
81 } 96 }
82 double result = trunc(left / right); 97 return DoubleToInteger(trunc(left / right),
83 if (isinf(result) || isnan(result)) { 98 "Result of truncating division is Infinity or NaN");
84 const Array& args = Array::Handle(Array::New(1));
85 args.SetAt(0, String::Handle(String::New(
86 "Result of truncating division is Infinity or NaN")));
87 Exceptions::ThrowByType(Exceptions::kUnsupported, args);
88 }
89 if ((Smi::kMinValue <= result) && (result <= Smi::kMaxValue)) {
90 return Smi::New(static_cast<intptr_t>(result));
91 } else if ((Mint::kMinValue <= result) && (result <= Mint::kMaxValue)) {
92 return Mint::New(static_cast<int64_t>(result));
93 } else {
94 return BigintOperations::NewFromDouble(result);
95 }
96 } 99 }
97 100
98 101
99 DEFINE_NATIVE_ENTRY(Double_modulo, 2) { 102 DEFINE_NATIVE_ENTRY(Double_modulo, 2) {
100 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); 103 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value();
101 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); 104 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1));
102 double right = right_object.value(); 105 double right = right_object.value();
103 106
104 double remainder = fmod_ieee(left, right); 107 double remainder = fmod_ieee(left, right);
105 if (remainder == 0.0) { 108 if (remainder == 0.0) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 197 }
195 198
196 199
197 #if defined(TARGET_OS_MACOS) 200 #if defined(TARGET_OS_MACOS)
198 // MAC OSX math library produces old style cast warning. 201 // MAC OSX math library produces old style cast warning.
199 #pragma GCC diagnostic ignored "-Wold-style-cast" 202 #pragma GCC diagnostic ignored "-Wold-style-cast"
200 #endif 203 #endif
201 204
202 DEFINE_NATIVE_ENTRY(Double_toInt, 1) { 205 DEFINE_NATIVE_ENTRY(Double_toInt, 1) {
203 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); 206 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0));
204 if (isinf(arg.value()) || isnan(arg.value())) { 207 return DoubleToInteger(arg.value(), "Infinity or NaN toInt");
205 const Array& args = Array::Handle(Array::New(1));
206 args.SetAt(0, String::Handle(String::New("Infinity or NaN toInt")));
207 Exceptions::ThrowByType(Exceptions::kUnsupported, args);
208 }
209 double result = trunc(arg.value());
210 if ((Smi::kMinValue <= result) && (result <= Smi::kMaxValue)) {
211 return Smi::New(static_cast<intptr_t>(result));
212 } else if ((Mint::kMinValue <= result) && (result <= Mint::kMaxValue)) {
213 return Mint::New(static_cast<int64_t>(result));
214 } else {
215 return BigintOperations::NewFromDouble(result);
216 }
217 } 208 }
218 209
219 210
220 DEFINE_NATIVE_ENTRY(Double_parse, 1) { 211 DEFINE_NATIVE_ENTRY(Double_parse, 1) {
221 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); 212 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0));
222 Scanner scanner(value, Symbols::Empty()); 213 Scanner scanner(value, Symbols::Empty());
223 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); 214 const Scanner::GrowableTokenStream& tokens = scanner.GetStream();
224 String* number_string; 215 String* number_string;
225 bool is_positive; 216 bool is_positive;
226 if (Scanner::IsValidLiteral(tokens, 217 if (Scanner::IsValidLiteral(tokens,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 333
343 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { 334 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) {
344 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); 335 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0));
345 // Include negative zero, infinity. 336 // Include negative zero, infinity.
346 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); 337 return Bool::Get(signbit(arg.value()) && !isnan(arg.value()));
347 } 338 }
348 339
349 // Add here only functions using/referring to old-style casts. 340 // Add here only functions using/referring to old-style casts.
350 341
351 } // namespace dart 342 } // namespace dart
OLDNEW
« 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