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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 | 117 |
118 void DoubleToStringConverter::CreateDecimalRepresentation( | 118 void DoubleToStringConverter::CreateDecimalRepresentation( |
119 const char* decimal_digits, | 119 const char* decimal_digits, |
120 int length, | 120 int length, |
121 int decimal_point, | 121 int decimal_point, |
122 int digits_after_point, | 122 int digits_after_point, |
123 StringBuilder* result_builder) const { | 123 StringBuilder* result_builder) const { |
124 // Create a representation that is padded with zeros if needed. | 124 // Create a representation that is padded with zeros if needed. |
125 if (decimal_point <= 0) { | 125 if (decimal_point <= 0) { |
126 // "0.00000decimal_rep". | 126 // "0.00000decimal_rep" or "0.000decimal_rep00". |
127 result_builder->AddCharacter('0'); | 127 result_builder->AddCharacter('0'); |
128 if (digits_after_point > 0) { | 128 if (digits_after_point > 0) { |
129 result_builder->AddCharacter('.'); | 129 result_builder->AddCharacter('.'); |
130 result_builder->AddPadding('0', -decimal_point); | 130 result_builder->AddPadding('0', -decimal_point); |
131 ASSERT(length <= digits_after_point - (-decimal_point)); | 131 ASSERT(length <= digits_after_point - (-decimal_point)); |
132 result_builder->AddSubstring(decimal_digits, length); | 132 result_builder->AddSubstring(decimal_digits, length); |
133 int remaining_digits = digits_after_point - (-decimal_point) - length; | 133 int remaining_digits = digits_after_point - (-decimal_point) - length; |
134 result_builder->AddPadding('0', remaining_digits); | 134 result_builder->AddPadding('0', remaining_digits); |
135 } | 135 } |
136 } else if (decimal_point >= length) { | 136 } else if (decimal_point >= length) { |
137 // "decimal_rep0000.00000" or "decimal_rep.0000" | 137 // "decimal_rep0000.00000" or "decimal_rep.0000". |
138 result_builder->AddSubstring(decimal_digits, length); | 138 result_builder->AddSubstring(decimal_digits, length); |
139 result_builder->AddPadding('0', decimal_point - length); | 139 result_builder->AddPadding('0', decimal_point - length); |
140 if (digits_after_point > 0) { | 140 if (digits_after_point > 0) { |
141 result_builder->AddCharacter('.'); | 141 result_builder->AddCharacter('.'); |
142 result_builder->AddPadding('0', digits_after_point); | 142 result_builder->AddPadding('0', digits_after_point); |
143 } | 143 } |
144 } else { | 144 } else { |
145 // "decima.l_rep000" | 145 // "decima.l_rep000". |
146 ASSERT(digits_after_point > 0); | 146 ASSERT(digits_after_point > 0); |
147 result_builder->AddSubstring(decimal_digits, decimal_point); | 147 result_builder->AddSubstring(decimal_digits, decimal_point); |
148 result_builder->AddCharacter('.'); | 148 result_builder->AddCharacter('.'); |
149 ASSERT(length - decimal_point <= digits_after_point); | 149 ASSERT(length - decimal_point <= digits_after_point); |
150 result_builder->AddSubstring(&decimal_digits[decimal_point], | 150 result_builder->AddSubstring(&decimal_digits[decimal_point], |
151 length - decimal_point); | 151 length - decimal_point); |
152 int remaining_digits = digits_after_point - (length - decimal_point); | 152 int remaining_digits = digits_after_point - (length - decimal_point); |
153 result_builder->AddPadding('0', remaining_digits); | 153 result_builder->AddPadding('0', remaining_digits); |
154 } | 154 } |
155 if (digits_after_point == 0) { | 155 if (digits_after_point == 0) { |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 | 982 |
983 float StringToDoubleConverter::StringToFloat( | 983 float StringToDoubleConverter::StringToFloat( |
984 const uc16* buffer, | 984 const uc16* buffer, |
985 int length, | 985 int length, |
986 int* processed_characters_count) const { | 986 int* processed_characters_count) const { |
987 return static_cast<float>(StringToIeee(buffer, length, false, | 987 return static_cast<float>(StringToIeee(buffer, length, false, |
988 processed_characters_count)); | 988 processed_characters_count)); |
989 } | 989 } |
990 | 990 |
991 } // namespace double_conversion | 991 } // namespace double_conversion |
OLD | NEW |