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

Unified Diff: runtime/lib/double.cc

Issue 11316031: - Move MathNatives from dart:core to dart:math. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | « no previous file | runtime/lib/double_patch.dart » ('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 14972)
+++ runtime/lib/double.cc (working copy)
@@ -11,6 +11,7 @@
#include "vm/exceptions.h"
#include "vm/native_entry.h"
#include "vm/object.h"
+#include "vm/symbols.h"
namespace dart {
@@ -202,6 +203,61 @@
}
+DEFINE_NATIVE_ENTRY(Double_parse, 1) {
+ GET_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0));
+ const String& dummy_key = String::Handle(Symbols::Empty());
+ Scanner scanner(value, dummy_key);
+ const Scanner::GrowableTokenStream& tokens = scanner.GetStream();
+ String* number_string;
+ bool is_positive;
+ if (Scanner::IsValidLiteral(tokens,
+ Token::kDOUBLE,
+ &is_positive,
+ &number_string)) {
+ const char* cstr = number_string->ToCString();
+ char* p_end = NULL;
+ double double_value = strtod(cstr, &p_end);
+ ASSERT(p_end != cstr);
+ if (!is_positive) {
+ double_value = -double_value;
+ }
+ return Double::New(double_value);
+ }
+
+ if (Scanner::IsValidLiteral(tokens,
+ Token::kINTEGER,
+ &is_positive,
+ &number_string)) {
+ Integer& res = Integer::Handle(Integer::New(*number_string));
+ if (is_positive) {
+ return Double::New(res.AsDoubleValue());
+ }
+ return Double::New(-res.AsDoubleValue());
+ }
+
+ // Infinity and nan.
+ if (Scanner::IsValidLiteral(tokens,
+ Token::kIDENT,
+ &is_positive,
+ &number_string)) {
+ if (number_string->Equals("NaN")) {
+ return Double::New(NAN);
+ }
+ if (number_string->Equals("Infinity")) {
+ if (is_positive) {
+ return Double::New(INFINITY);
+ }
+ return Double::New(-INFINITY);
+ }
+ }
+
+ GrowableArray<const Object*> args;
+ args.Add(&value);
+ Exceptions::ThrowByType(Exceptions::kFormat, args);
+ return Object::null();
+}
+
+
DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) {
// The boundaries are exclusive.
static const double kLowerBoundary = -1e21;
« no previous file with comments | « no previous file | runtime/lib/double_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698