| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/double_conversion.h" | 5 #include "vm/double_conversion.h" |
| 6 | 6 |
| 7 #include "third_party/double-conversion/src/double-conversion.h" | 7 #include "third_party/double-conversion/src/double-conversion.h" |
| 8 | 8 |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 kDoubleToStringCommonInfinitySymbol, | 84 kDoubleToStringCommonInfinitySymbol, |
| 85 kDoubleToStringCommonNaNSymbol, | 85 kDoubleToStringCommonNaNSymbol, |
| 86 kDoubleToStringCommonExponentChar, | 86 kDoubleToStringCommonExponentChar, |
| 87 0, 0, 0, 0); // Last four values are ignored in fixed mode. | 87 0, 0, 0, 0); // Last four values are ignored in fixed mode. |
| 88 | 88 |
| 89 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); | 89 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); |
| 90 buffer[kBufferSize - 1] = '\0'; | 90 buffer[kBufferSize - 1] = '\0'; |
| 91 double_conversion::StringBuilder builder(buffer, kBufferSize); | 91 double_conversion::StringBuilder builder(buffer, kBufferSize); |
| 92 bool status = converter.ToFixed(d, fraction_digits, &builder); | 92 bool status = converter.ToFixed(d, fraction_digits, &builder); |
| 93 ASSERT(status); | 93 ASSERT(status); |
| 94 int length = builder.position(); | 94 return String::New(builder.Finalize()); |
| 95 return String::New(reinterpret_cast<uint8_t*>(builder.Finalize()), length); | |
| 96 } | 95 } |
| 97 | 96 |
| 98 | 97 |
| 99 RawString* DoubleToStringAsExponential(double d, int fraction_digits) { | 98 RawString* DoubleToStringAsExponential(double d, int fraction_digits) { |
| 100 static const int kMinFractionDigits = -1; // -1 represents shortest mode. | 99 static const int kMinFractionDigits = -1; // -1 represents shortest mode. |
| 101 static const int kMaxFractionDigits = 20; | 100 static const int kMaxFractionDigits = 20; |
| 102 static const int kConversionFlags = | 101 static const int kConversionFlags = |
| 103 double_conversion::DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN; | 102 double_conversion::DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN; |
| 104 const int kBufferSize = 128; | 103 const int kBufferSize = 128; |
| 105 | 104 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 118 kDoubleToStringCommonInfinitySymbol, | 117 kDoubleToStringCommonInfinitySymbol, |
| 119 kDoubleToStringCommonNaNSymbol, | 118 kDoubleToStringCommonNaNSymbol, |
| 120 kDoubleToStringCommonExponentChar, | 119 kDoubleToStringCommonExponentChar, |
| 121 0, 0, 0, 0); // Last four values are ignored in exponential mode. | 120 0, 0, 0, 0); // Last four values are ignored in exponential mode. |
| 122 | 121 |
| 123 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); | 122 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); |
| 124 buffer[kBufferSize - 1] = '\0'; | 123 buffer[kBufferSize - 1] = '\0'; |
| 125 double_conversion::StringBuilder builder(buffer, kBufferSize); | 124 double_conversion::StringBuilder builder(buffer, kBufferSize); |
| 126 bool status = converter.ToExponential(d, fraction_digits, &builder); | 125 bool status = converter.ToExponential(d, fraction_digits, &builder); |
| 127 ASSERT(status); | 126 ASSERT(status); |
| 128 int length = builder.position(); | 127 return String::New(builder.Finalize()); |
| 129 return String::New(reinterpret_cast<uint8_t*>(builder.Finalize()), length); | |
| 130 } | 128 } |
| 131 | 129 |
| 132 | 130 |
| 133 RawString* DoubleToStringAsPrecision(double d, int precision) { | 131 RawString* DoubleToStringAsPrecision(double d, int precision) { |
| 134 static const int kMinPrecisionDigits = 1; | 132 static const int kMinPrecisionDigits = 1; |
| 135 static const int kMaxPrecisionDigits = 21; | 133 static const int kMaxPrecisionDigits = 21; |
| 136 static const int kMaxLeadingPaddingZeroes = 6; | 134 static const int kMaxLeadingPaddingZeroes = 6; |
| 137 static const int kMaxTrailingPaddingZeroes = 0; | 135 static const int kMaxTrailingPaddingZeroes = 0; |
| 138 static const int kConversionFlags = | 136 static const int kConversionFlags = |
| 139 double_conversion::DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN; | 137 double_conversion::DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 158 kDoubleToStringCommonExponentChar, | 156 kDoubleToStringCommonExponentChar, |
| 159 0, 0, // Ignored in precision mode. | 157 0, 0, // Ignored in precision mode. |
| 160 kMaxLeadingPaddingZeroes, | 158 kMaxLeadingPaddingZeroes, |
| 161 kMaxTrailingPaddingZeroes); | 159 kMaxTrailingPaddingZeroes); |
| 162 | 160 |
| 163 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); | 161 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); |
| 164 buffer[kBufferSize - 1] = '\0'; | 162 buffer[kBufferSize - 1] = '\0'; |
| 165 double_conversion::StringBuilder builder(buffer, kBufferSize); | 163 double_conversion::StringBuilder builder(buffer, kBufferSize); |
| 166 bool status = converter.ToPrecision(d, precision, &builder); | 164 bool status = converter.ToPrecision(d, precision, &builder); |
| 167 ASSERT(status); | 165 ASSERT(status); |
| 168 int length = builder.position(); | 166 return String::New(builder.Finalize()); |
| 169 return String::New(reinterpret_cast<uint8_t*>(builder.Finalize()), length); | |
| 170 } | 167 } |
| 171 | 168 |
| 172 } // namespace dart | 169 } // namespace dart |
| OLD | NEW |