54bool DoubleToStringConverter::HandleSpecialValues(
57 Double double_inspect(value);
58 if (double_inspect.IsInfinite()) {
63 result_builder->
AddString(infinity_symbol_);
66 if (double_inspect.IsNan()) {
75void DoubleToStringConverter::CreateExponentialRepresentation(
76 const char* decimal_digits,
79 StringBuilder* result_builder)
const {
81 result_builder->AddCharacter(decimal_digits[0]);
84 result_builder->AddCharacter(
'.');
86 result_builder->AddCharacter(
'0');
90 result_builder->AddCharacter(
'.');
91 result_builder->AddSubstring(&decimal_digits[1],
length-1);
93 result_builder->AddCharacter(exponent_character_);
95 result_builder->AddCharacter(
'-');
99 result_builder->AddCharacter(
'+');
104 const int kMaxExponentLength = 5;
105 char buffer[kMaxExponentLength + 1];
106 buffer[kMaxExponentLength] =
'\0';
107 int first_char_pos = kMaxExponentLength;
109 buffer[--first_char_pos] =
'0';
111 while (exponent > 0) {
112 buffer[--first_char_pos] =
'0' + (exponent % 10);
118 while(kMaxExponentLength - first_char_pos < std::min(min_exponent_width_, kMaxExponentLength)) {
119 buffer[--first_char_pos] =
'0';
121 result_builder->AddSubstring(&
buffer[first_char_pos],
122 kMaxExponentLength - first_char_pos);
126void DoubleToStringConverter::CreateDecimalRepresentation(
127 const char* decimal_digits,
130 int digits_after_point,
131 StringBuilder* result_builder)
const {
133 if (decimal_point <= 0) {
135 result_builder->AddCharacter(
'0');
136 if (digits_after_point > 0) {
137 result_builder->AddCharacter(
'.');
138 result_builder->AddPadding(
'0', -decimal_point);
140 result_builder->AddSubstring(decimal_digits,
length);
141 int remaining_digits = digits_after_point - (-decimal_point) -
length;
142 result_builder->AddPadding(
'0', remaining_digits);
144 }
else if (decimal_point >=
length) {
146 result_builder->AddSubstring(decimal_digits,
length);
147 result_builder->AddPadding(
'0', decimal_point -
length);
148 if (digits_after_point > 0) {
149 result_builder->AddCharacter(
'.');
150 result_builder->AddPadding(
'0', digits_after_point);
155 result_builder->AddSubstring(decimal_digits, decimal_point);
156 result_builder->AddCharacter(
'.');
158 result_builder->AddSubstring(&decimal_digits[decimal_point],
160 int remaining_digits = digits_after_point - (
length - decimal_point);
161 result_builder->AddPadding(
'0', remaining_digits);
163 if (digits_after_point == 0) {
165 result_builder->AddCharacter(
'.');
168 result_builder->AddCharacter(
'0');
174bool DoubleToStringConverter::ToShortestIeeeNumber(
176 StringBuilder* result_builder,
179 if (Double(value).IsSpecial()) {
180 return HandleSpecialValues(value, result_builder);
186 char decimal_rep[kDecimalRepCapacity];
187 int decimal_rep_length;
189 DoubleToAscii(value, mode, 0, decimal_rep, kDecimalRepCapacity,
190 &
sign, &decimal_rep_length, &decimal_point);
193 if (
sign && (value != 0.0 || !unique_zero)) {
194 result_builder->AddCharacter(
'-');
197 int exponent = decimal_point - 1;
198 if ((decimal_in_shortest_low_ <= exponent) &&
199 (exponent < decimal_in_shortest_high_)) {
200 CreateDecimalRepresentation(decimal_rep, decimal_rep_length,
202 (std::max)(0, decimal_rep_length - decimal_point),
205 CreateExponentialRepresentation(decimal_rep, decimal_rep_length, exponent,
213 int requested_digits,
216 const double kFirstNonFixed = 1e60;
219 return HandleSpecialValues(
value, result_builder);
223 if (
value >= kFirstNonFixed ||
value <= -kFirstNonFixed)
return false;
229 const int kDecimalRepCapacity =
231 char decimal_rep[kDecimalRepCapacity];
232 int decimal_rep_length;
234 decimal_rep, kDecimalRepCapacity,
235 &
sign, &decimal_rep_length, &decimal_point);
238 if (
sign && (
value != 0.0 || !unique_zero)) {
242 CreateDecimalRepresentation(decimal_rep, decimal_rep_length, decimal_point,
243 requested_digits, result_builder);
250 int requested_digits,
253 return HandleSpecialValues(
value, result_builder);
256 if (requested_digits < -1)
return false;
264 char decimal_rep[kDecimalRepCapacity];
269 memset(decimal_rep, 0,
sizeof(decimal_rep));
271 int decimal_rep_length;
273 if (requested_digits == -1) {
275 decimal_rep, kDecimalRepCapacity,
276 &
sign, &decimal_rep_length, &decimal_point);
279 decimal_rep, kDecimalRepCapacity,
280 &
sign, &decimal_rep_length, &decimal_point);
283 for (
int i = decimal_rep_length; i < requested_digits + 1; ++i) {
284 decimal_rep[i] =
'0';
286 decimal_rep_length = requested_digits + 1;
290 if (
sign && (
value != 0.0 || !unique_zero)) {
294 int exponent = decimal_point - 1;
295 CreateExponentialRepresentation(decimal_rep,
307 return HandleSpecialValues(
value, result_builder);
319 char decimal_rep[kDecimalRepCapacity];
320 int decimal_rep_length;
323 decimal_rep, kDecimalRepCapacity,
324 &
sign, &decimal_rep_length, &decimal_point);
328 if (
sign && (
value != 0.0 || !unique_zero)) {
334 int exponent = decimal_point - 1;
337 bool as_exponential =
338 (-decimal_point + 1 > max_leading_padding_zeroes_in_precision_mode_) ||
339 (decimal_point - precision + extra_zero >
340 max_trailing_padding_zeroes_in_precision_mode_);
344 int stop = as_exponential ? 1 : std::max(1, decimal_point);
345 while (decimal_rep_length > stop && decimal_rep[decimal_rep_length - 1] ==
'0') {
346 --decimal_rep_length;
349 precision = std::min(precision, decimal_rep_length);
351 if (as_exponential) {
355 for (
int i = decimal_rep_length; i < precision; ++i) {
356 decimal_rep[i] =
'0';
359 CreateExponentialRepresentation(decimal_rep,
364 CreateDecimalRepresentation(decimal_rep, decimal_rep_length, decimal_point,
365 (std::max)(0, precision - decimal_point),
388 int requested_digits,
398 if (
Double(v).Sign() < 0) {
405 if (mode ==
PRECISION && requested_digits == 0) {
439 if (fast_worked)
return;
static int sign(SkScalar x)
static const int kMaxFixedDigitsAfterPoint
bool ToFixed(double value, int requested_digits, StringBuilder *result_builder) const
static const DoubleToStringConverter & EcmaScriptConverter()
bool ToExponential(double value, int requested_digits, StringBuilder *result_builder) const
static const int kMaxFixedDigitsBeforePoint
static void DoubleToAscii(double v, DtoaMode mode, int requested_digits, char *buffer, int buffer_length, bool *sign, int *length, int *point)
static const int kMaxPrecisionDigits
@ EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL
@ EMIT_POSITIVE_EXPONENT_SIGN
@ EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL
@ EMIT_TRAILING_ZERO_AFTER_POINT
@ EMIT_TRAILING_DECIMAL_POINT
static const int kBase10MaximalLength
static const int kMaxExponentialDigits
bool ToPrecision(double value, int precision, StringBuilder *result_builder) const
void AddCharacter(char c)
void AddString(const char *s)
FlutterSemanticsFlag flags
static const uint8_t buffer[]
void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits, Vector< char > buffer, int *length, int *decimal_point)
@ BIGNUM_DTOA_SHORTEST_SINGLE
@ FAST_DTOA_SHORTEST_SINGLE
static BignumDtoaMode DtoaToBignumDtoaMode(DoubleToStringConverter::DtoaMode dtoa_mode)
bool FastDtoa(double v, FastDtoaMode mode, int requested_digits, Vector< char > buffer, int *length, int *decimal_point)
bool FastFixedDtoa(double v, int fractional_count, Vector< char > buffer, int *length, int *decimal_point)
#define DOUBLE_CONVERSION_NULLPTR
#define DOUBLE_CONVERSION_ASSERT(condition)
#define DOUBLE_CONVERSION_UNREACHABLE()