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 = reinterpret_cast<char*>( | 89 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); |
90 Isolate::Current()->current_zone()->Allocate(kBufferSize)); | |
91 buffer[kBufferSize - 1] = '\0'; | 90 buffer[kBufferSize - 1] = '\0'; |
92 double_conversion::StringBuilder builder(buffer, kBufferSize); | 91 double_conversion::StringBuilder builder(buffer, kBufferSize); |
93 bool status = converter.ToFixed(d, fraction_digits, &builder); | 92 bool status = converter.ToFixed(d, fraction_digits, &builder); |
94 ASSERT(status); | 93 ASSERT(status); |
95 int length = builder.position(); | 94 int length = builder.position(); |
96 return String::New(reinterpret_cast<uint8_t*>(builder.Finalize()), length); | 95 return String::New(reinterpret_cast<uint8_t*>(builder.Finalize()), length); |
97 } | 96 } |
98 | 97 |
99 | 98 |
100 RawString* DoubleToStringAsExponential(double d, int fraction_digits) { | 99 RawString* DoubleToStringAsExponential(double d, int fraction_digits) { |
(...skipping 13 matching lines...) Expand all Loading... |
114 ASSERT(kMinFractionDigits <= fraction_digits && | 113 ASSERT(kMinFractionDigits <= fraction_digits && |
115 fraction_digits <= kMaxFractionDigits); | 114 fraction_digits <= kMaxFractionDigits); |
116 | 115 |
117 const double_conversion::DoubleToStringConverter converter( | 116 const double_conversion::DoubleToStringConverter converter( |
118 kConversionFlags, | 117 kConversionFlags, |
119 kDoubleToStringCommonInfinitySymbol, | 118 kDoubleToStringCommonInfinitySymbol, |
120 kDoubleToStringCommonNaNSymbol, | 119 kDoubleToStringCommonNaNSymbol, |
121 kDoubleToStringCommonExponentChar, | 120 kDoubleToStringCommonExponentChar, |
122 0, 0, 0, 0); // Last four values are ignored in exponential mode. | 121 0, 0, 0, 0); // Last four values are ignored in exponential mode. |
123 | 122 |
124 char* buffer = reinterpret_cast<char*>( | 123 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); |
125 Isolate::Current()->current_zone()->Allocate(kBufferSize)); | |
126 buffer[kBufferSize - 1] = '\0'; | 124 buffer[kBufferSize - 1] = '\0'; |
127 double_conversion::StringBuilder builder(buffer, kBufferSize); | 125 double_conversion::StringBuilder builder(buffer, kBufferSize); |
128 bool status = converter.ToExponential(d, fraction_digits, &builder); | 126 bool status = converter.ToExponential(d, fraction_digits, &builder); |
129 ASSERT(status); | 127 ASSERT(status); |
130 int length = builder.position(); | 128 int length = builder.position(); |
131 return String::New(reinterpret_cast<uint8_t*>(builder.Finalize()), length); | 129 return String::New(reinterpret_cast<uint8_t*>(builder.Finalize()), length); |
132 } | 130 } |
133 | 131 |
134 | 132 |
135 RawString* DoubleToStringAsPrecision(double d, int precision) { | 133 RawString* DoubleToStringAsPrecision(double d, int precision) { |
(...skipping 19 matching lines...) Expand all Loading... |
155 | 153 |
156 const double_conversion::DoubleToStringConverter converter( | 154 const double_conversion::DoubleToStringConverter converter( |
157 kConversionFlags, | 155 kConversionFlags, |
158 kDoubleToStringCommonInfinitySymbol, | 156 kDoubleToStringCommonInfinitySymbol, |
159 kDoubleToStringCommonNaNSymbol, | 157 kDoubleToStringCommonNaNSymbol, |
160 kDoubleToStringCommonExponentChar, | 158 kDoubleToStringCommonExponentChar, |
161 0, 0, // Ignored in precision mode. | 159 0, 0, // Ignored in precision mode. |
162 kMaxLeadingPaddingZeroes, | 160 kMaxLeadingPaddingZeroes, |
163 kMaxTrailingPaddingZeroes); | 161 kMaxTrailingPaddingZeroes); |
164 | 162 |
165 char* buffer = reinterpret_cast<char*>( | 163 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); |
166 Isolate::Current()->current_zone()->Allocate(kBufferSize)); | |
167 buffer[kBufferSize - 1] = '\0'; | 164 buffer[kBufferSize - 1] = '\0'; |
168 double_conversion::StringBuilder builder(buffer, kBufferSize); | 165 double_conversion::StringBuilder builder(buffer, kBufferSize); |
169 bool status = converter.ToPrecision(d, precision, &builder); | 166 bool status = converter.ToPrecision(d, precision, &builder); |
170 ASSERT(status); | 167 ASSERT(status); |
171 int length = builder.position(); | 168 int length = builder.position(); |
172 return String::New(reinterpret_cast<uint8_t*>(builder.Finalize()), length); | 169 return String::New(reinterpret_cast<uint8_t*>(builder.Finalize()), length); |
173 } | 170 } |
174 | 171 |
175 } // namespace dart | 172 } // namespace dart |
OLD | NEW |