Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: src/conversions.cc

Issue 3564011: During StringToDouble negative exponents may be less than -999 with a result ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/cctest/test-conversions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 const int kMaxDigitsInInt = 9 * sizeof(int) / 4; // NOLINT 658 const int kMaxDigitsInInt = 9 * sizeof(int) / 4; // NOLINT
659 659
660 if (exponent != 0) { 660 if (exponent != 0) {
661 ASSERT(buffer_pos < kBufferSize); 661 ASSERT(buffer_pos < kBufferSize);
662 buffer[buffer_pos++] = 'e'; 662 buffer[buffer_pos++] = 'e';
663 if (exponent < 0) { 663 if (exponent < 0) {
664 ASSERT(buffer_pos < kBufferSize); 664 ASSERT(buffer_pos < kBufferSize);
665 buffer[buffer_pos++] = '-'; 665 buffer[buffer_pos++] = '-';
666 exponent = -exponent; 666 exponent = -exponent;
667 } 667 }
668 if (exponent > 999) exponent = 999; // Result will be Infinity or 0 or -0.
669 668
670 const int exp_digits = 3; 669 // The minimal/maximal double is +/-1.7e-308. Given that
670 // the buffer contains at most 773 (kMaxSignificantDigits + 1) the
671 // minimal possible exponent is hence -(308 + 773)=-1081.
672 // Since leading zeros are removed the maximal exponent cannot exceed 308.
673 // If the following test triggers the result will be +/-infinity or +/-0.
674 if (exponent > 9999) exponent = 9999;
675
676 const int exp_digits = 4;
671 for (int i = 0; i < exp_digits; i++) { 677 for (int i = 0; i < exp_digits; i++) {
672 buffer[buffer_pos + exp_digits - 1 - i] = '0' + exponent % 10; 678 buffer[buffer_pos + exp_digits - 1 - i] = '0' + exponent % 10;
673 exponent /= 10; 679 exponent /= 10;
674 } 680 }
675 ASSERT(exponent == 0); 681 ASSERT(exponent == 0);
676 buffer_pos += exp_digits; 682 buffer_pos += exp_digits;
677 } else if (!fractional_part && significant_digits <= kMaxDigitsInInt) { 683 } else if (!fractional_part && significant_digits <= kMaxDigitsInInt) {
678 if (significant_digits == 0) return SignedZero(sign); 684 if (significant_digits == 0) return SignedZero(sign);
679 ASSERT(buffer_pos > 0); 685 ASSERT(buffer_pos > 0);
680 int num = 0; 686 int num = 0;
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 // Allocate result and fill in the parts. 1171 // Allocate result and fill in the parts.
1166 StringBuilder builder(result_size + 1); 1172 StringBuilder builder(result_size + 1);
1167 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); 1173 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size);
1168 if (decimal_pos > 0) builder.AddCharacter('.'); 1174 if (decimal_pos > 0) builder.AddCharacter('.');
1169 builder.AddSubstring(decimal_buffer, decimal_pos); 1175 builder.AddSubstring(decimal_buffer, decimal_pos);
1170 return builder.Finalize(); 1176 return builder.Finalize();
1171 } 1177 }
1172 1178
1173 1179
1174 } } // namespace v8::internal 1180 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698