OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 const int kBufferSize = kMaxSignificantDigits + 10; | 447 const int kBufferSize = kMaxSignificantDigits + 10; |
448 char buffer[kBufferSize]; // NOLINT: size is known at compile time. | 448 char buffer[kBufferSize]; // NOLINT: size is known at compile time. |
449 int buffer_pos = 0; | 449 int buffer_pos = 0; |
450 | 450 |
451 // Exponent will be adjusted if insignificant digits of the integer part | 451 // Exponent will be adjusted if insignificant digits of the integer part |
452 // or insignificant leading zeros of the fractional part are dropped. | 452 // or insignificant leading zeros of the fractional part are dropped. |
453 int exponent = 0; | 453 int exponent = 0; |
454 int significant_digits = 0; | 454 int significant_digits = 0; |
455 int insignificant_digits = 0; | 455 int insignificant_digits = 0; |
456 bool nonzero_digit_dropped = false; | 456 bool nonzero_digit_dropped = false; |
457 bool fractional_part = false; | |
458 | 457 |
459 bool negative = false; | 458 bool negative = false; |
460 | 459 |
461 if (*current == '+') { | 460 if (*current == '+') { |
462 // Ignore leading sign. | 461 // Ignore leading sign. |
463 ++current; | 462 ++current; |
464 if (current == end) return JunkStringValue(); | 463 if (current == end) return JunkStringValue(); |
465 } else if (*current == '-') { | 464 } else if (*current == '-') { |
466 ++current; | 465 ++current; |
467 if (current == end) return JunkStringValue(); | 466 if (current == end) return JunkStringValue(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // octal = false; | 549 // octal = false; |
551 // Integer part consists of 0 or is absent. Significant digits start after | 550 // Integer part consists of 0 or is absent. Significant digits start after |
552 // leading zeros (if any). | 551 // leading zeros (if any). |
553 while (*current == '0') { | 552 while (*current == '0') { |
554 ++current; | 553 ++current; |
555 if (current == end) return SignedZero(negative); | 554 if (current == end) return SignedZero(negative); |
556 exponent--; // Move this 0 into the exponent. | 555 exponent--; // Move this 0 into the exponent. |
557 } | 556 } |
558 } | 557 } |
559 | 558 |
560 // We don't emit a '.', but adjust the exponent instead. | 559 // There is a fractional part. We don't emit a '.', but adjust the exponent |
561 fractional_part = true; | 560 // instead. |
562 | |
563 // There is a fractional part. | |
564 while (*current >= '0' && *current <= '9') { | 561 while (*current >= '0' && *current <= '9') { |
565 if (significant_digits < kMaxSignificantDigits) { | 562 if (significant_digits < kMaxSignificantDigits) { |
566 ASSERT(buffer_pos < kBufferSize); | 563 ASSERT(buffer_pos < kBufferSize); |
567 buffer[buffer_pos++] = static_cast<char>(*current); | 564 buffer[buffer_pos++] = static_cast<char>(*current); |
568 significant_digits++; | 565 significant_digits++; |
569 exponent--; | 566 exponent--; |
570 } else { | 567 } else { |
571 // Ignore insignificant digits in the fractional part. | 568 // Ignore insignificant digits in the fractional part. |
572 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; | 569 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; |
573 } | 570 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 ASSERT(buffer_pos < kBufferSize); | 655 ASSERT(buffer_pos < kBufferSize); |
659 buffer[buffer_pos] = '\0'; | 656 buffer[buffer_pos] = '\0'; |
660 | 657 |
661 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 658 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
662 return negative ? -converted : converted; | 659 return negative ? -converted : converted; |
663 } | 660 } |
664 | 661 |
665 } } // namespace v8::internal | 662 } } // namespace v8::internal |
666 | 663 |
667 #endif // V8_CONVERSIONS_INL_H_ | 664 #endif // V8_CONVERSIONS_INL_H_ |
OLD | NEW |