| 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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 695 |
| 696 double StringToDouble(Vector<const char> str, | 696 double StringToDouble(Vector<const char> str, |
| 697 int flags, | 697 int flags, |
| 698 double empty_string_val) { | 698 double empty_string_val) { |
| 699 const char* end = str.start() + str.length(); | 699 const char* end = str.start() + str.length(); |
| 700 return InternalStringToDouble(str.start(), end, flags, empty_string_val); | 700 return InternalStringToDouble(str.start(), end, flags, empty_string_val); |
| 701 } | 701 } |
| 702 | 702 |
| 703 | 703 |
| 704 const char* DoubleToCString(double v, Vector<char> buffer) { | 704 const char* DoubleToCString(double v, Vector<char> buffer) { |
| 705 StringBuilder builder(buffer.start(), buffer.length()); | |
| 706 | |
| 707 switch (fpclassify(v)) { | 705 switch (fpclassify(v)) { |
| 708 case FP_NAN: | 706 case FP_NAN: return "NaN"; |
| 709 builder.AddString("NaN"); | 707 case FP_INFINITE: return (v < 0.0 ? "-Infinity" : "Infinity"); |
| 710 break; | 708 case FP_ZERO: return "0"; |
| 711 | |
| 712 case FP_INFINITE: | |
| 713 if (v < 0.0) { | |
| 714 builder.AddString("-Infinity"); | |
| 715 } else { | |
| 716 builder.AddString("Infinity"); | |
| 717 } | |
| 718 break; | |
| 719 | |
| 720 case FP_ZERO: | |
| 721 builder.AddCharacter('0'); | |
| 722 break; | |
| 723 | |
| 724 default: { | 709 default: { |
| 710 StringBuilder builder(buffer.start(), buffer.length()); |
| 725 int decimal_point; | 711 int decimal_point; |
| 726 int sign; | 712 int sign; |
| 727 const int kV8DtoaBufferCapacity = kBase10MaximalLength + 1; | 713 const int kV8DtoaBufferCapacity = kBase10MaximalLength + 1; |
| 728 char decimal_rep[kV8DtoaBufferCapacity]; | 714 char decimal_rep[kV8DtoaBufferCapacity]; |
| 729 int length; | 715 int length; |
| 730 | 716 |
| 731 DoubleToAscii(v, DTOA_SHORTEST, 0, | 717 DoubleToAscii(v, DTOA_SHORTEST, 0, |
| 732 Vector<char>(decimal_rep, kV8DtoaBufferCapacity), | 718 Vector<char>(decimal_rep, kV8DtoaBufferCapacity), |
| 733 &sign, &length, &decimal_point); | 719 &sign, &length, &decimal_point); |
| 734 | 720 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 757 if (length != 1) { | 743 if (length != 1) { |
| 758 builder.AddCharacter('.'); | 744 builder.AddCharacter('.'); |
| 759 builder.AddString(decimal_rep + 1); | 745 builder.AddString(decimal_rep + 1); |
| 760 } | 746 } |
| 761 builder.AddCharacter('e'); | 747 builder.AddCharacter('e'); |
| 762 builder.AddCharacter((decimal_point >= 0) ? '+' : '-'); | 748 builder.AddCharacter((decimal_point >= 0) ? '+' : '-'); |
| 763 int exponent = decimal_point - 1; | 749 int exponent = decimal_point - 1; |
| 764 if (exponent < 0) exponent = -exponent; | 750 if (exponent < 0) exponent = -exponent; |
| 765 builder.AddFormatted("%d", exponent); | 751 builder.AddFormatted("%d", exponent); |
| 766 } | 752 } |
| 753 return builder.Finalize(); |
| 767 } | 754 } |
| 768 } | 755 } |
| 769 return builder.Finalize(); | |
| 770 } | 756 } |
| 771 | 757 |
| 772 | 758 |
| 773 const char* IntToCString(int n, Vector<char> buffer) { | 759 const char* IntToCString(int n, Vector<char> buffer) { |
| 774 bool negative = false; | 760 bool negative = false; |
| 775 if (n < 0) { | 761 if (n < 0) { |
| 776 // We must not negate the most negative int. | 762 // We must not negate the most negative int. |
| 777 if (n == kMinInt) return DoubleToCString(n, buffer); | 763 if (n == kMinInt) return DoubleToCString(n, buffer); |
| 778 negative = true; | 764 negative = true; |
| 779 n = -n; | 765 n = -n; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 // Allocate result and fill in the parts. | 1060 // Allocate result and fill in the parts. |
| 1075 StringBuilder builder(result_size + 1); | 1061 StringBuilder builder(result_size + 1); |
| 1076 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); | 1062 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); |
| 1077 if (decimal_pos > 0) builder.AddCharacter('.'); | 1063 if (decimal_pos > 0) builder.AddCharacter('.'); |
| 1078 builder.AddSubstring(decimal_buffer, decimal_pos); | 1064 builder.AddSubstring(decimal_buffer, decimal_pos); |
| 1079 return builder.Finalize(); | 1065 return builder.Finalize(); |
| 1080 } | 1066 } |
| 1081 | 1067 |
| 1082 | 1068 |
| 1083 } } // namespace v8::internal | 1069 } } // namespace v8::internal |
| OLD | NEW |