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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 ASSERT(kMinFractionDigits <= fraction_digits && | 79 ASSERT(kMinFractionDigits <= fraction_digits && |
80 fraction_digits <= kMaxFractionDigits); | 80 fraction_digits <= kMaxFractionDigits); |
81 | 81 |
82 const double_conversion::DoubleToStringConverter converter( | 82 const double_conversion::DoubleToStringConverter converter( |
83 kConversionFlags, | 83 kConversionFlags, |
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 = Thread::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 return String::New(builder.Finalize()); | 94 return String::New(builder.Finalize()); |
95 } | 95 } |
96 | 96 |
97 | 97 |
98 RawString* DoubleToStringAsExponential(double d, int fraction_digits) { | 98 RawString* DoubleToStringAsExponential(double d, int fraction_digits) { |
99 static const int kMinFractionDigits = -1; // -1 represents shortest mode. | 99 static const int kMinFractionDigits = -1; // -1 represents shortest mode. |
(...skipping 12 matching lines...) Expand all Loading... |
112 ASSERT(kMinFractionDigits <= fraction_digits && | 112 ASSERT(kMinFractionDigits <= fraction_digits && |
113 fraction_digits <= kMaxFractionDigits); | 113 fraction_digits <= kMaxFractionDigits); |
114 | 114 |
115 const double_conversion::DoubleToStringConverter converter( | 115 const double_conversion::DoubleToStringConverter converter( |
116 kConversionFlags, | 116 kConversionFlags, |
117 kDoubleToStringCommonInfinitySymbol, | 117 kDoubleToStringCommonInfinitySymbol, |
118 kDoubleToStringCommonNaNSymbol, | 118 kDoubleToStringCommonNaNSymbol, |
119 kDoubleToStringCommonExponentChar, | 119 kDoubleToStringCommonExponentChar, |
120 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. |
121 | 121 |
122 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); | 122 char* buffer = Thread::Current()->zone()->Alloc<char>(kBufferSize); |
123 buffer[kBufferSize - 1] = '\0'; | 123 buffer[kBufferSize - 1] = '\0'; |
124 double_conversion::StringBuilder builder(buffer, kBufferSize); | 124 double_conversion::StringBuilder builder(buffer, kBufferSize); |
125 bool status = converter.ToExponential(d, fraction_digits, &builder); | 125 bool status = converter.ToExponential(d, fraction_digits, &builder); |
126 ASSERT(status); | 126 ASSERT(status); |
127 return String::New(builder.Finalize()); | 127 return String::New(builder.Finalize()); |
128 } | 128 } |
129 | 129 |
130 | 130 |
131 RawString* DoubleToStringAsPrecision(double d, int precision) { | 131 RawString* DoubleToStringAsPrecision(double d, int precision) { |
132 static const int kMinPrecisionDigits = 1; | 132 static const int kMinPrecisionDigits = 1; |
(...skipping 18 matching lines...) Expand all Loading... |
151 | 151 |
152 const double_conversion::DoubleToStringConverter converter( | 152 const double_conversion::DoubleToStringConverter converter( |
153 kConversionFlags, | 153 kConversionFlags, |
154 kDoubleToStringCommonInfinitySymbol, | 154 kDoubleToStringCommonInfinitySymbol, |
155 kDoubleToStringCommonNaNSymbol, | 155 kDoubleToStringCommonNaNSymbol, |
156 kDoubleToStringCommonExponentChar, | 156 kDoubleToStringCommonExponentChar, |
157 0, 0, // Ignored in precision mode. | 157 0, 0, // Ignored in precision mode. |
158 kMaxLeadingPaddingZeroes, | 158 kMaxLeadingPaddingZeroes, |
159 kMaxTrailingPaddingZeroes); | 159 kMaxTrailingPaddingZeroes); |
160 | 160 |
161 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); | 161 char* buffer = Thread::Current()->zone()->Alloc<char>(kBufferSize); |
162 buffer[kBufferSize - 1] = '\0'; | 162 buffer[kBufferSize - 1] = '\0'; |
163 double_conversion::StringBuilder builder(buffer, kBufferSize); | 163 double_conversion::StringBuilder builder(buffer, kBufferSize); |
164 bool status = converter.ToPrecision(d, precision, &builder); | 164 bool status = converter.ToPrecision(d, precision, &builder); |
165 ASSERT(status); | 165 ASSERT(status); |
166 return String::New(builder.Finalize()); | 166 return String::New(builder.Finalize()); |
167 } | 167 } |
168 | 168 |
169 | 169 |
170 bool CStringToDouble(const char* str, intptr_t length, double* result) { | 170 bool CStringToDouble(const char* str, intptr_t length, double* result) { |
171 if (length == 0) { | 171 if (length == 0) { |
172 return false; | 172 return false; |
173 } | 173 } |
174 | 174 |
175 double_conversion::StringToDoubleConverter converter( | 175 double_conversion::StringToDoubleConverter converter( |
176 double_conversion::StringToDoubleConverter::NO_FLAGS, | 176 double_conversion::StringToDoubleConverter::NO_FLAGS, |
177 0.0, | 177 0.0, |
178 0.0, | 178 0.0, |
179 kDoubleToStringCommonInfinitySymbol, | 179 kDoubleToStringCommonInfinitySymbol, |
180 kDoubleToStringCommonNaNSymbol); | 180 kDoubleToStringCommonNaNSymbol); |
181 | 181 |
182 int parsed_count = 0; | 182 int parsed_count = 0; |
183 *result = converter.StringToDouble(str, | 183 *result = converter.StringToDouble(str, |
184 static_cast<int>(length), | 184 static_cast<int>(length), |
185 &parsed_count); | 185 &parsed_count); |
186 return (parsed_count == length); | 186 return (parsed_count == length); |
187 } | 187 } |
188 | 188 |
189 | 189 |
190 } // namespace dart | 190 } // namespace dart |
OLD | NEW |