OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 const int kBufferSize = kMaxSignificantDigits + 10; | 597 const int kBufferSize = kMaxSignificantDigits + 10; |
598 char buffer[kBufferSize]; // NOLINT: size is known at compile time. | 598 char buffer[kBufferSize]; // NOLINT: size is known at compile time. |
599 int buffer_pos = 0; | 599 int buffer_pos = 0; |
600 | 600 |
601 // Exponent will be adjusted if insignificant digits of the integer part | 601 // Exponent will be adjusted if insignificant digits of the integer part |
602 // or insignificant leading zeros of the fractional part are dropped. | 602 // or insignificant leading zeros of the fractional part are dropped. |
603 int exponent = 0; | 603 int exponent = 0; |
604 int significant_digits = 0; | 604 int significant_digits = 0; |
605 int insignificant_digits = 0; | 605 int insignificant_digits = 0; |
606 bool nonzero_digit_dropped = false; | 606 bool nonzero_digit_dropped = false; |
607 bool fractional_part = false; | |
608 | 607 |
609 bool sign = false; | 608 bool sign = false; |
610 | 609 |
611 if (*current == '+' || *current == '-') { | 610 if (*current == '+' || *current == '-') { |
612 sign = (*current == '-'); | 611 sign = (*current == '-'); |
613 ++current; | 612 ++current; |
614 const char* next_non_space = current; | 613 const char* next_non_space = current; |
615 // Skip following spaces (if allowed). | 614 // Skip following spaces (if allowed). |
616 if (!AdvanceToNonspace(&next_non_space, end)) return junk_string_value_; | 615 if (!AdvanceToNonspace(&next_non_space, end)) return junk_string_value_; |
617 if (!allow_spaces_after_sign && (current != next_non_space)) { | 616 if (!allow_spaces_after_sign && (current != next_non_space)) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 while (*current == '0') { | 740 while (*current == '0') { |
742 ++current; | 741 ++current; |
743 if (current == end) { | 742 if (current == end) { |
744 *processed_characters_count = current - input; | 743 *processed_characters_count = current - input; |
745 return SignedZero(sign); | 744 return SignedZero(sign); |
746 } | 745 } |
747 exponent--; // Move this 0 into the exponent. | 746 exponent--; // Move this 0 into the exponent. |
748 } | 747 } |
749 } | 748 } |
750 | 749 |
| 750 // There is a fractional part. |
751 // We don't emit a '.', but adjust the exponent instead. | 751 // We don't emit a '.', but adjust the exponent instead. |
752 fractional_part = true; | |
753 | |
754 // There is a fractional part. | |
755 while (*current >= '0' && *current <= '9') { | 752 while (*current >= '0' && *current <= '9') { |
756 if (significant_digits < kMaxSignificantDigits) { | 753 if (significant_digits < kMaxSignificantDigits) { |
757 ASSERT(buffer_pos < kBufferSize); | 754 ASSERT(buffer_pos < kBufferSize); |
758 buffer[buffer_pos++] = static_cast<char>(*current); | 755 buffer[buffer_pos++] = static_cast<char>(*current); |
759 significant_digits++; | 756 significant_digits++; |
760 exponent--; | 757 exponent--; |
761 } else { | 758 } else { |
762 // Ignore insignificant digits in the fractional part. | 759 // Ignore insignificant digits in the fractional part. |
763 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; | 760 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; |
764 } | 761 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 857 |
861 ASSERT(buffer_pos < kBufferSize); | 858 ASSERT(buffer_pos < kBufferSize); |
862 buffer[buffer_pos] = '\0'; | 859 buffer[buffer_pos] = '\0'; |
863 | 860 |
864 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 861 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
865 *processed_characters_count = current - input; | 862 *processed_characters_count = current - input; |
866 return sign? -converted: converted; | 863 return sign? -converted: converted; |
867 } | 864 } |
868 | 865 |
869 } // namespace double_conversion | 866 } // namespace double_conversion |
OLD | NEW |