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

Side by Side Diff: runtime/vm/object.cc

Issue 9113043: Implement Double.{toString, toStringAsExponential, toStringAsPrecision} (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment Created 8 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
11 #include "vm/code_generator.h" 11 #include "vm/code_generator.h"
12 #include "vm/code_index_table.h" 12 #include "vm/code_index_table.h"
13 #include "vm/code_patcher.h" 13 #include "vm/code_patcher.h"
14 #include "vm/compiler.h" 14 #include "vm/compiler.h"
15 #include "vm/compiler_stats.h" 15 #include "vm/compiler_stats.h"
16 #include "vm/class_finalizer.h" 16 #include "vm/class_finalizer.h"
17 #include "vm/dart.h" 17 #include "vm/dart.h"
18 #include "vm/dart_entry.h" 18 #include "vm/dart_entry.h"
19 #include "vm/debuginfo.h" 19 #include "vm/debuginfo.h"
20 #include "vm/double_conversion.h"
20 #include "vm/exceptions.h" 21 #include "vm/exceptions.h"
21 #include "vm/growable_array.h" 22 #include "vm/growable_array.h"
22 #include "vm/heap.h" 23 #include "vm/heap.h"
23 #include "vm/ic_data.h" 24 #include "vm/ic_data.h"
24 #include "vm/object_store.h" 25 #include "vm/object_store.h"
25 #include "vm/parser.h" 26 #include "vm/parser.h"
26 #include "vm/runtime_entry.h" 27 #include "vm/runtime_entry.h"
27 #include "vm/scopes.h" 28 #include "vm/scopes.h"
28 #include "vm/timer.h" 29 #include "vm/timer.h"
29 #include "vm/unicode.h" 30 #include "vm/unicode.h"
(...skipping 5930 matching lines...) Expand 10 before | Expand all | Expand 10 after
5960 } 5961 }
5961 5962
5962 5963
5963 const char* Double::ToCString() const { 5964 const char* Double::ToCString() const {
5964 if (isnan(value())) { 5965 if (isnan(value())) {
5965 return "NaN"; 5966 return "NaN";
5966 } 5967 }
5967 if (isinf(value())) { 5968 if (isinf(value())) {
5968 return value() < 0 ? "-Infinity" : "Infinity"; 5969 return value() < 0 ? "-Infinity" : "Infinity";
5969 } 5970 }
5970 const char* kFormat = "%f"; 5971 const int kBufferSize = 128;
5971 // Calculate the size of the string. 5972 char buffer[kBufferSize];
5972 intptr_t len = OS::SNPrint(NULL, 0, kFormat, value()) + 1; 5973 int len;
5974 bool status = DoubleToCString(value(), buffer, kBufferSize, &len);
5975 ASSERT(status);
5976
5973 char* chars = reinterpret_cast<char*>( 5977 char* chars = reinterpret_cast<char*>(
5974 Isolate::Current()->current_zone()->Allocate(len)); 5978 Isolate::Current()->current_zone()->Allocate(len));
5975 OS::SNPrint(chars, len, kFormat, value()); 5979 memmove(chars, buffer, len);
5976 // Eliminate trailing 0s, but leave one digit after '.'.
5977 // 'chars' is null terminated.
5978 for (intptr_t i = len - 2; i >= 1; i--) {
5979 if ((chars[i] == '0') && (chars[i - 1] != '.')) {
5980 chars[i] = '\0';
5981 } else {
5982 break;
5983 }
5984 }
5985 return chars; 5980 return chars;
5986 } 5981 }
5987 5982
5988 5983
5989 bool Bigint::Equals(const Instance& other) const { 5984 bool Bigint::Equals(const Instance& other) const {
5990 if (this->raw() == other.raw()) { 5985 if (this->raw() == other.raw()) {
5991 // Both handles point to the same raw instance. 5986 // Both handles point to the same raw instance.
5992 return true; 5987 return true;
5993 } 5988 }
5994 5989
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after
7782 const String& str = String::Handle(pattern()); 7777 const String& str = String::Handle(pattern());
7783 const char* format = "JSRegExp: pattern=%s flags=%s"; 7778 const char* format = "JSRegExp: pattern=%s flags=%s";
7784 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 7779 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
7785 char* chars = reinterpret_cast<char*>( 7780 char* chars = reinterpret_cast<char*>(
7786 Isolate::Current()->current_zone()->Allocate(len + 1)); 7781 Isolate::Current()->current_zone()->Allocate(len + 1));
7787 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 7782 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
7788 return chars; 7783 return chars;
7789 } 7784 }
7790 7785
7791 } // namespace dart 7786 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698