OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (current == end) break; | 347 if (current == end) break; |
348 } | 348 } |
349 | 349 |
350 if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) { | 350 if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) { |
351 return JUNK_STRING_VALUE; | 351 return JUNK_STRING_VALUE; |
352 } | 352 } |
353 | 353 |
354 ASSERT(buffer_pos < kBufferSize); | 354 ASSERT(buffer_pos < kBufferSize); |
355 buffer[buffer_pos] = '\0'; | 355 buffer[buffer_pos] = '\0'; |
356 Vector<char> buffer_vector(buffer, buffer_pos); | 356 Vector<char> buffer_vector(buffer, buffer_pos); |
357 return sign ? -Strtod(buffer_vector, 0) : Strtod(buffer_vector, 0); | 357 return sign ? -strtod(buffer_vector, NULL) : strtod(buffer_vector, NULL); |
358 } | 358 } |
359 | 359 |
360 // The following code causes accumulating rounding error for numbers greater | 360 // The following code causes accumulating rounding error for numbers greater |
361 // than ~2^56. It's explicitly allowed in the spec: "if R is not 2, 4, 8, 10, | 361 // than ~2^56. It's explicitly allowed in the spec: "if R is not 2, 4, 8, 10, |
362 // 16, or 32, then mathInt may be an implementation-dependent approximation to | 362 // 16, or 32, then mathInt may be an implementation-dependent approximation to |
363 // the mathematical integer value" (15.1.2.2). | 363 // the mathematical integer value" (15.1.2.2). |
364 | 364 |
365 int lim_0 = '0' + (radix < 10 ? radix : 10); | 365 int lim_0 = '0' + (radix < 10 ? radix : 10); |
366 int lim_a = 'a' + (radix - 10); | 366 int lim_a = 'a' + (radix - 10); |
367 int lim_A = 'A' + (radix - 10); | 367 int lim_A = 'A' + (radix - 10); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 } | 646 } |
647 | 647 |
648 if (nonzero_digit_dropped) { | 648 if (nonzero_digit_dropped) { |
649 buffer[buffer_pos++] = '1'; | 649 buffer[buffer_pos++] = '1'; |
650 exponent--; | 650 exponent--; |
651 } | 651 } |
652 | 652 |
653 ASSERT(buffer_pos < kBufferSize); | 653 ASSERT(buffer_pos < kBufferSize); |
654 buffer[buffer_pos] = '\0'; | 654 buffer[buffer_pos] = '\0'; |
655 | 655 |
656 double converted = Strtod(Vector<char>(buffer, buffer_pos), exponent); | 656 double converted = strtod(Vector<char>(buffer, buffer_pos), exponent); |
657 return sign? -converted: converted; | 657 return sign? -converted: converted; |
658 } | 658 } |
659 | 659 |
660 | 660 |
661 double StringToDouble(String* str, int flags, double empty_string_val) { | 661 double StringToDouble(String* str, int flags, double empty_string_val) { |
662 StringShape shape(str); | 662 StringShape shape(str); |
663 if (shape.IsSequentialAscii()) { | 663 if (shape.IsSequentialAscii()) { |
664 const char* begin = SeqAsciiString::cast(str)->GetChars(); | 664 const char* begin = SeqAsciiString::cast(str)->GetChars(); |
665 const char* end = begin + str->length(); | 665 const char* end = begin + str->length(); |
666 return InternalStringToDouble(begin, end, flags, empty_string_val); | 666 return InternalStringToDouble(begin, end, flags, empty_string_val); |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 // Allocate result and fill in the parts. | 1131 // Allocate result and fill in the parts. |
1132 StringBuilder builder(result_size + 1); | 1132 StringBuilder builder(result_size + 1); |
1133 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); | 1133 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); |
1134 if (decimal_pos > 0) builder.AddCharacter('.'); | 1134 if (decimal_pos > 0) builder.AddCharacter('.'); |
1135 builder.AddSubstring(decimal_buffer, decimal_pos); | 1135 builder.AddSubstring(decimal_buffer, decimal_pos); |
1136 return builder.Finalize(); | 1136 return builder.Finalize(); |
1137 } | 1137 } |
1138 | 1138 |
1139 | 1139 |
1140 } } // namespace v8::internal | 1140 } } // namespace v8::internal |
OLD | NEW |