42 const char* str,
int flags,
double empty_string_val) {
52 double empty_string_val) {
61 double empty_string_val) {
71 case FP_INFINITE:
return (v < 0.0 ?
"-Infinity" :
"Infinity");
78 char decimal_rep[kV8DtoaBufferCapacity];
83 &sign, &length, &decimal_point);
85 if (sign) builder.AddCharacter(
'-');
87 if (length <= decimal_point && decimal_point <= 21) {
89 builder.AddString(decimal_rep);
90 builder.AddPadding(
'0', decimal_point - length);
92 }
else if (0 < decimal_point && decimal_point <= 21) {
94 builder.AddSubstring(decimal_rep, decimal_point);
95 builder.AddCharacter(
'.');
96 builder.AddString(decimal_rep + decimal_point);
98 }
else if (decimal_point <= 0 && decimal_point > -6) {
100 builder.AddString(
"0.");
101 builder.AddPadding(
'0', -decimal_point);
102 builder.AddString(decimal_rep);
106 builder.AddCharacter(decimal_rep[0]);
108 builder.AddCharacter(
'.');
109 builder.AddString(decimal_rep + 1);
111 builder.AddCharacter(
'e');
112 builder.AddCharacter((decimal_point >= 0) ?
'+' :
'-');
113 int exponent = decimal_point - 1;
114 if (exponent < 0) exponent = -exponent;
115 builder.AddDecimalInteger(exponent);
117 return builder.Finalize();
135 buffer[--i] =
'0' + (n % 10);
138 if (negative) buffer[--i] =
'-';
139 return buffer.
start() + i;
144 const int kMaxDigitsBeforePoint = 21;
145 const double kFirstNonFixed = 1e21;
146 const int kMaxDigitsAfterPoint = 20;
148 ASSERT(f <= kMaxDigitsAfterPoint);
151 double abs_value = value;
159 if (abs_value >= kFirstNonFixed) {
169 const int kDecimalRepCapacity =
170 kMaxDigitsBeforePoint + kMaxDigitsAfterPoint + 1;
171 char decimal_rep[kDecimalRepCapacity];
172 int decimal_rep_length;
175 &sign, &decimal_rep_length, &decimal_point);
178 int zero_prefix_length = 0;
179 int zero_postfix_length = 0;
181 if (decimal_point <= 0) {
182 zero_prefix_length = -decimal_point + 1;
186 if (zero_prefix_length + decimal_rep_length < decimal_point + f) {
187 zero_postfix_length = decimal_point + f - decimal_rep_length -
191 unsigned rep_length =
192 zero_prefix_length + decimal_rep_length + zero_postfix_length;
194 rep_builder.
AddPadding(
'0', zero_prefix_length);
196 rep_builder.
AddPadding(
'0', zero_postfix_length);
201 unsigned result_size = decimal_point + f + 2;
214 static char* CreateExponentialRepresentation(
char* decimal_rep,
217 int significant_digits) {
218 bool negative_exponent =
false;
220 negative_exponent =
true;
221 exponent = -exponent;
227 unsigned result_size = significant_digits + 7;
228 SimpleStringBuilder builder(result_size + 1);
230 if (negative) builder.AddCharacter(
'-');
231 builder.AddCharacter(decimal_rep[0]);
232 if (significant_digits != 1) {
233 builder.AddCharacter(
'.');
234 builder.AddString(decimal_rep + 1);
236 builder.AddPadding(
'0', significant_digits - rep_length);
239 builder.AddCharacter(
'e');
240 builder.AddCharacter(negative_exponent ?
'-' :
'+');
241 builder.AddDecimalInteger(exponent);
242 return builder.Finalize();
248 const int kMaxDigitsAfterPoint = 20;
250 ASSERT(f >= -1 && f <= kMaxDigitsAfterPoint);
252 bool negative =
false;
264 const int kV8DtoaBufferCapacity = kMaxDigitsAfterPoint + 1 + 1;
268 char decimal_rep[kV8DtoaBufferCapacity];
269 int decimal_rep_length;
274 &sign, &decimal_rep_length, &decimal_point);
275 f = decimal_rep_length - 1;
279 &sign, &decimal_rep_length, &decimal_point);
281 ASSERT(decimal_rep_length > 0);
282 ASSERT(decimal_rep_length <= f + 1);
284 int exponent = decimal_point - 1;
286 CreateExponentialRepresentation(decimal_rep, exponent, negative, f+1);
293 const int kMinimalDigits = 1;
294 const int kMaximalDigits = 21;
295 ASSERT(p >= kMinimalDigits && p <= kMaximalDigits);
298 bool negative =
false;
308 const int kV8DtoaBufferCapacity = kMaximalDigits + 1;
309 char decimal_rep[kV8DtoaBufferCapacity];
310 int decimal_rep_length;
314 &sign, &decimal_rep_length, &decimal_point);
315 ASSERT(decimal_rep_length <= p);
317 int exponent = decimal_point - 1;
321 if (exponent < -6 || exponent >= p) {
323 CreateExponentialRepresentation(decimal_rep, exponent, negative, p);
330 unsigned result_size = (decimal_point <= 0)
331 ? -decimal_point + p + 3
335 if (decimal_point <= 0) {
339 builder.
AddPadding(
'0', p - decimal_rep_length);
341 const int m =
Min(decimal_rep_length, decimal_point);
343 builder.
AddPadding(
'0', decimal_point - decimal_rep_length);
344 if (decimal_point < p) {
346 const int extra = negative ? 2 : 1;
347 if (decimal_rep_length > decimal_point) {
348 const int len =
StrLength(decimal_rep + decimal_point);
349 const int n =
Min(len, p - (builder.
position() - extra));
363 ASSERT(radix >= 2 && radix <= 36);
366 static const char chars[] =
"0123456789abcdefghijklmnopqrstuvwxyz";
370 static const int kBufferSize = 1100;
371 char integer_buffer[kBufferSize];
372 integer_buffer[kBufferSize - 1] =
'\0';
376 char decimal_buffer[kBufferSize];
377 decimal_buffer[kBufferSize - 1] =
'\0';
380 bool is_negative = value < 0.0;
381 if (is_negative) value = -value;
384 double integer_part = floor(value);
385 double decimal_part = value - integer_part;
389 int integer_pos = kBufferSize - 2;
391 integer_buffer[integer_pos--] =
392 chars[
static_cast<int>(fmod(integer_part, radix))];
393 integer_part /= radix;
394 }
while (integer_part >= 1.0);
398 if (is_negative) integer_buffer[integer_pos--] =
'-';
410 while ((decimal_part > 0.0) && (decimal_pos < kBufferSize - 1)) {
411 decimal_part *= radix;
412 decimal_buffer[decimal_pos++] =
413 chars[
static_cast<int>(floor(decimal_part))];
414 decimal_part -= floor(decimal_part);
416 decimal_buffer[decimal_pos] =
'\0';
419 int integer_part_size = kBufferSize - 2 - integer_pos;
421 unsigned result_size = integer_part_size + decimal_pos;
423 if (decimal_pos > 0) result_size++;
426 builder.
AddSubstring(integer_buffer + integer_pos + 1, integer_part_size);
void AddString(const char *s)
double InternalStringToDouble(UnicodeCache *unicode_cache, Iterator current, EndMark end, int flags, double empty_string_val)
#define ASSERT(condition)
double StringToDouble(UnicodeCache *unicode_cache, const char *str, int flags, double empty_string_val)
const char * IntToCString(int n, Vector< char > buffer)
const char * DoubleToCString(double v, Vector< char > buffer)
int StrLength(const char *string)
char * DoubleToPrecisionCString(double value, int p)
void AddSubstring(const char *s, int n)
void AddCharacter(char c)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
void AddPadding(char c, int count)
char * StrDup(const char *str)
char * DoubleToExponentialCString(double value, int f)
void DoubleToAscii(double v, DtoaMode mode, int requested_digits, Vector< char > buffer, int *sign, int *length, int *point)
char * DoubleToRadixCString(double value, int radix)
void DeleteArray(T *array)
const int kBase10MaximalLength
char * DoubleToFixedCString(double value, int f)