28 #ifndef V8_CONVERSIONS_INL_H_
29 #define V8_CONVERSIONS_INL_H_
70 const double k2Pow52 = 4503599627370496.0;
80 memcpy(&result, mantissa_ptr,
sizeof(result));
81 return negative ? ~result + 1 : result;
89 if (
isnan(x))
return 0;
90 if (!
isfinite(x) || x == 0)
return x;
91 return (x >= 0) ? floor(x) : ceil(x);
104 if (exponent > 31)
return 0;
110 template <
class Iterator,
class EndMark>
113 const char* substring) {
114 ASSERT(**current == *substring);
115 for (substring++; *substring !=
'\0'; substring++) {
117 if (*current == end || **current != *substring)
return false;
126 template <
class Iterator,
class EndMark>
130 while (*current != end) {
131 if (!unicode_cache->
IsWhiteSpace(**current))
return true;
139 template <
int radix_log_2,
class Iterator,
class EndMark>
144 bool allow_trailing_junk) {
148 while (*current ==
'0') {
150 if (current == end)
return SignedZero(negative);
155 const int radix = (1 << radix_log_2);
159 if (*current >=
'0' && *current <=
'9' && *current <
'0' + radix) {
160 digit =
static_cast<char>(*current) -
'0';
161 }
else if (radix > 10 && *current >=
'a' && *current <
'a' + radix - 10) {
162 digit =
static_cast<char>(*current) -
'a' + 10;
163 }
else if (radix > 10 && *current >=
'A' && *current <
'A' + radix - 10) {
164 digit =
static_cast<char>(*current) -
'A' + 10;
166 if (allow_trailing_junk ||
174 number = number * radix + digit;
175 int overflow =
static_cast<int>(number >> 53);
179 int overflow_bits_count = 1;
180 while (overflow > 1) {
181 overflow_bits_count++;
185 int dropped_bits_mask = ((1 << overflow_bits_count) - 1);
186 int dropped_bits =
static_cast<int>(number) & dropped_bits_mask;
187 number >>= overflow_bits_count;
188 exponent = overflow_bits_count;
190 bool zero_tail =
true;
193 if (current == end || !
isDigit(*current, radix))
break;
194 zero_tail = zero_tail && *current ==
'0';
195 exponent += radix_log_2;
198 if (!allow_trailing_junk &&
203 int middle_value = (1 << (overflow_bits_count - 1));
204 if (dropped_bits > middle_value) {
206 }
else if (dropped_bits == middle_value) {
209 if ((number & 1) != 0 || !zero_tail) {
215 if ((number & ((int64_t)1 << 53)) != 0) {
222 }
while (current != end);
224 ASSERT(number < ((int64_t)1 << 53));
225 ASSERT(static_cast<int64_t>(static_cast<double>(number)) == number);
229 if (number == 0)
return -0.0;
232 return static_cast<double>(number);
236 return ldexp(static_cast<double>(negative ? -number : number), exponent);
240 template <
class Iterator,
class EndMark>
245 const bool allow_trailing_junk =
true;
249 return empty_string_val;
253 bool leading_zero =
false;
255 if (*current ==
'+') {
258 if (current == end) {
261 }
else if (*current ==
'-') {
263 if (current == end) {
272 if (*current ==
'0') {
274 if (current == end)
return SignedZero(negative);
275 if (*current ==
'x' || *current ==
'X') {
283 }
else if (radix == 16) {
284 if (*current ==
'0') {
287 if (current == end)
return SignedZero(negative);
288 if (*current ==
'x' || *current ==
'X') {
300 while (*current ==
'0') {
303 if (current == end)
return SignedZero(negative);
306 if (!leading_zero && !
isDigit(*current, radix)) {
313 return InternalStringToIntDouble<1>(
314 unicode_cache, current, end,
negative, allow_trailing_junk);
316 return InternalStringToIntDouble<2>(
317 unicode_cache, current, end,
negative, allow_trailing_junk);
319 return InternalStringToIntDouble<3>(
320 unicode_cache, current, end,
negative, allow_trailing_junk);
323 return InternalStringToIntDouble<4>(
324 unicode_cache, current, end,
negative, allow_trailing_junk);
327 return InternalStringToIntDouble<5>(
328 unicode_cache, current, end,
negative, allow_trailing_junk);
339 const int kBufferSize = kMaxSignificantDigits + 2;
340 char buffer[kBufferSize];
342 while (*current >=
'0' && *current <=
'9') {
343 if (buffer_pos <= kMaxSignificantDigits) {
346 ASSERT(buffer_pos < kBufferSize);
347 buffer[buffer_pos++] =
static_cast<char>(*current);
350 if (current == end)
break;
353 if (!allow_trailing_junk &&
358 ASSERT(buffer_pos < kBufferSize);
359 buffer[buffer_pos] =
'\0';
361 return negative ? -
Strtod(buffer_vector, 0) :
Strtod(buffer_vector, 0);
369 int lim_0 =
'0' + (radix < 10 ? radix : 10);
370 int lim_a =
'a' + (radix - 10);
371 int lim_A =
'A' + (radix - 10);
383 unsigned int part = 0, multiplier = 1;
386 if (*current >=
'0' && *current < lim_0) {
388 }
else if (*current >=
'a' && *current < lim_a) {
389 d = *current -
'a' + 10;
390 }
else if (*current >=
'A' && *current < lim_A) {
391 d = *current -
'A' + 10;
401 const unsigned int kMaximumMultiplier = 0xffffffff
U / 36;
402 uint32_t m = multiplier * radix;
403 if (m > kMaximumMultiplier)
break;
404 part = part * radix + d;
406 ASSERT(multiplier > part);
409 if (current == end) {
416 v = v * multiplier + part;
419 if (!allow_trailing_junk &&
424 return negative ? -v : v;
433 template <
class Iterator,
class EndMark>
438 double empty_string_val) {
448 return empty_string_val;
455 char buffer[kBufferSize];
461 int significant_digits = 0;
462 int insignificant_digits = 0;
463 bool nonzero_digit_dropped =
false;
473 if (*current ==
'+') {
478 }
else if (*current ==
'-') {
484 static const char kInfinitySymbol[] =
"Infinity";
485 if (*current == kInfinitySymbol[0]) {
490 if (!allow_trailing_junk &&
499 bool leading_zero =
false;
500 if (*current ==
'0') {
502 if (current == end)
return SignedZero(sign == NEGATIVE);
507 if ((flags &
ALLOW_HEX) && (*current ==
'x' || *current ==
'X')) {
509 if (current == end || !
isDigit(*current, 16) || sign !=
NONE) {
513 return InternalStringToIntDouble<4>(unicode_cache,
517 allow_trailing_junk);
521 while (*current ==
'0') {
523 if (current == end)
return SignedZero(sign == NEGATIVE);
527 bool octal = leading_zero && (flags &
ALLOW_OCTALS) != 0;
530 while (*current >=
'0' && *current <=
'9') {
532 ASSERT(buffer_pos < kBufferSize);
533 buffer[buffer_pos++] =
static_cast<char>(*current);
534 significant_digits++;
537 insignificant_digits++;
538 nonzero_digit_dropped = nonzero_digit_dropped || *current !=
'0';
540 octal = octal && *current <
'8';
542 if (current == end)
goto parsing_done;
545 if (significant_digits == 0) {
549 if (*current ==
'.') {
551 if (octal)
goto parsing_done;
554 if (current == end) {
555 if (significant_digits == 0 && !leading_zero) {
562 if (significant_digits == 0) {
566 while (*current ==
'0') {
568 if (current == end)
return SignedZero(sign == NEGATIVE);
575 while (*current >=
'0' && *current <=
'9') {
577 ASSERT(buffer_pos < kBufferSize);
578 buffer[buffer_pos++] =
static_cast<char>(*current);
579 significant_digits++;
583 nonzero_digit_dropped = nonzero_digit_dropped || *current !=
'0';
586 if (current == end)
goto parsing_done;
590 if (!leading_zero && exponent == 0 && significant_digits == 0) {
599 if (*current ==
'e' || *current ==
'E') {
602 if (current == end) {
603 if (allow_trailing_junk) {
610 if (*current ==
'+' || *current ==
'-') {
611 sign =
static_cast<char>(*current);
613 if (current == end) {
614 if (allow_trailing_junk) {
622 if (current == end || *current < '0' || *current >
'9') {
623 if (allow_trailing_junk) {
630 const int max_exponent = INT_MAX / 2;
631 ASSERT(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2);
635 int digit = *current -
'0';
636 if (num >= max_exponent / 10
637 && !(num == max_exponent / 10 && digit <= max_exponent % 10)) {
640 num = num * 10 + digit;
643 }
while (current != end && *current >=
'0' && *current <=
'9');
645 exponent += (sign ==
'-' ? -num : num);
648 if (!allow_trailing_junk &&
654 exponent += insignificant_digits;
657 return InternalStringToIntDouble<3>(unicode_cache,
661 allow_trailing_junk);
664 if (nonzero_digit_dropped) {
665 buffer[buffer_pos++] =
'1';
669 ASSERT(buffer_pos < kBufferSize);
670 buffer[buffer_pos] =
'\0';
673 return (sign == NEGATIVE) ? -converted : converted;
678 #endif // V8_CONVERSIONS_INL_H_
uint64_t Significand() const
double InternalStringToDouble(UnicodeCache *unicode_cache, Iterator current, EndMark end, int flags, double empty_string_val)
double DoubleToInteger(double x)
bool SubStringEquals(Iterator *current, EndMark end, const char *substring)
const uint64_t kQuietNaNMask
bool isDigit(int x, int radix)
bool IsWhiteSpace(unibrow::uchar c)
double InternalStringToInt(UnicodeCache *unicode_cache, Iterator current, EndMark end, int radix)
#define ASSERT(condition)
static const int kSignificandSize
double Strtod(Vector< const char > buffer, int exponent)
double SignedZero(bool negative)
static const uint64_t kSignMask
unsigned int FastD2UI(double x)
double uint64_to_double(uint64_t d64)
double InternalStringToIntDouble(UnicodeCache *unicode_cache, Iterator current, EndMark end, bool negative, bool allow_trailing_junk)
bool AdvanceToNonspace(UnicodeCache *unicode_cache, Iterator *current, EndMark end)
const int kMaxSignificantDigits
int32_t DoubleToInt32(double x)
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 use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra 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 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the Print usage including flags