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

Side by Side Diff: src/conversions.cc

Issue 973001: Version 2.1.4.1... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 10 years, 9 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 | « src/checks.h ('k') | src/diy_fp.h » ('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 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdarg.h> 28 #include <stdarg.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #include "conversions-inl.h" 32 #include "conversions-inl.h"
33 #include "factory.h" 33 #include "factory.h"
34 #include "grisu3.h"
35 #include "scanner.h" 34 #include "scanner.h"
36 35
37 namespace v8 { 36 namespace v8 {
38 namespace internal { 37 namespace internal {
39 38
40 int HexValue(uc32 c) { 39 int HexValue(uc32 c) {
41 if ('0' <= c && c <= '9') 40 if ('0' <= c && c <= '9')
42 return c - '0'; 41 return c - '0';
43 if ('a' <= c && c <= 'f') 42 if ('a' <= c && c <= 'f')
44 return c - 'a' + 10; 43 return c - 'a' + 10;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 break; 375 break;
377 376
378 case FP_ZERO: 377 case FP_ZERO:
379 builder.AddCharacter('0'); 378 builder.AddCharacter('0');
380 break; 379 break;
381 380
382 default: { 381 default: {
383 int decimal_point; 382 int decimal_point;
384 int sign; 383 int sign;
385 384
386 char* decimal_rep; 385 char* decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL);
387 bool used_dtoa = false; 386 int length = StrLength(decimal_rep);
388 char grisu_buffer[kGrisu3MaximalLength + 1];
389 int length;
390 if (grisu3(v, grisu_buffer, &sign, &length, &decimal_point)) {
391 decimal_rep = grisu_buffer;
392 } else {
393 decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL);
394 used_dtoa = true;
395 length = StrLength(decimal_rep);
396 }
397 387
398 if (sign) builder.AddCharacter('-'); 388 if (sign) builder.AddCharacter('-');
399 389
400 if (length <= decimal_point && decimal_point <= 21) { 390 if (length <= decimal_point && decimal_point <= 21) {
401 // ECMA-262 section 9.8.1 step 6. 391 // ECMA-262 section 9.8.1 step 6.
402 builder.AddString(decimal_rep); 392 builder.AddString(decimal_rep);
403 builder.AddPadding('0', decimal_point - length); 393 builder.AddPadding('0', decimal_point - length);
404 394
405 } else if (0 < decimal_point && decimal_point <= 21) { 395 } else if (0 < decimal_point && decimal_point <= 21) {
406 // ECMA-262 section 9.8.1 step 7. 396 // ECMA-262 section 9.8.1 step 7.
(...skipping 14 matching lines...) Expand all
421 builder.AddCharacter('.'); 411 builder.AddCharacter('.');
422 builder.AddString(decimal_rep + 1); 412 builder.AddString(decimal_rep + 1);
423 } 413 }
424 builder.AddCharacter('e'); 414 builder.AddCharacter('e');
425 builder.AddCharacter((decimal_point >= 0) ? '+' : '-'); 415 builder.AddCharacter((decimal_point >= 0) ? '+' : '-');
426 int exponent = decimal_point - 1; 416 int exponent = decimal_point - 1;
427 if (exponent < 0) exponent = -exponent; 417 if (exponent < 0) exponent = -exponent;
428 builder.AddFormatted("%d", exponent); 418 builder.AddFormatted("%d", exponent);
429 } 419 }
430 420
431 if (used_dtoa) freedtoa(decimal_rep); 421 freedtoa(decimal_rep);
432 } 422 }
433 } 423 }
434 return builder.Finalize(); 424 return builder.Finalize();
435 } 425 }
436 426
437 427
438 const char* IntToCString(int n, Vector<char> buffer) { 428 const char* IntToCString(int n, Vector<char> buffer) {
439 bool negative = false; 429 bool negative = false;
440 if (n < 0) { 430 if (n < 0) {
441 // We must not negate the most negative int. 431 // We must not negate the most negative int.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 // Allocate result and fill in the parts. 700 // Allocate result and fill in the parts.
711 StringBuilder builder(result_size + 1); 701 StringBuilder builder(result_size + 1);
712 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); 702 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size);
713 if (decimal_pos > 0) builder.AddCharacter('.'); 703 if (decimal_pos > 0) builder.AddCharacter('.');
714 builder.AddSubstring(decimal_buffer, decimal_pos); 704 builder.AddSubstring(decimal_buffer, decimal_pos);
715 return builder.Finalize(); 705 return builder.Finalize();
716 } 706 }
717 707
718 708
719 } } // namespace v8::internal 709 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/checks.h ('k') | src/diy_fp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698