mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-06 15:55:00 +00:00
Optimize shortest float formatting
This commit is contained in:
parent
1db2274966
commit
8a06cee826
@ -3194,16 +3194,6 @@ FMT_CONSTEXPR20 auto format_float(Float value, int precision,
|
|||||||
exp = static_cast<int>(e);
|
exp = static_cast<int>(e);
|
||||||
if (e > exp) ++exp; // Compute ceil.
|
if (e > exp) ++exp; // Compute ceil.
|
||||||
dragon_flags = dragon::fixup;
|
dragon_flags = dragon::fixup;
|
||||||
} else if (precision < 0) {
|
|
||||||
// Use Dragonbox for the shortest format.
|
|
||||||
if (binary32) {
|
|
||||||
auto dec = dragonbox::to_decimal(static_cast<float>(value));
|
|
||||||
write<char>(appender(buf), dec.significand);
|
|
||||||
return dec.exponent;
|
|
||||||
}
|
|
||||||
auto dec = dragonbox::to_decimal(static_cast<double>(value));
|
|
||||||
write<char>(appender(buf), dec.significand);
|
|
||||||
return dec.exponent;
|
|
||||||
} else {
|
} else {
|
||||||
// Extract significand bits and exponent bits.
|
// Extract significand bits and exponent bits.
|
||||||
using info = dragonbox::float_info<double>;
|
using info = dragonbox::float_info<double>;
|
||||||
@ -3497,9 +3487,18 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
|
|||||||
specs);
|
specs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int precision = specs.precision >= 0 || specs.type == presentation_type::none
|
int precision = specs.precision;
|
||||||
? specs.precision
|
if (precision < 0) {
|
||||||
: 6;
|
if (specs.type != presentation_type::none) {
|
||||||
|
precision = 6;
|
||||||
|
} else if (is_fast_float<T>::value && !is_constant_evaluated()) {
|
||||||
|
// Use Dragonbox for the shortest format.
|
||||||
|
using floaty = conditional_t<sizeof(T) >= sizeof(double), double, float>;
|
||||||
|
auto dec = dragonbox::to_decimal(static_cast<floaty>(value));
|
||||||
|
return write_float<Char>(out, dec, specs, sign, loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (specs.type == presentation_type::exp) {
|
if (specs.type == presentation_type::exp) {
|
||||||
if (precision == max_value<int>())
|
if (precision == max_value<int>())
|
||||||
report_error("number is too big");
|
report_error("number is too big");
|
||||||
@ -3511,7 +3510,6 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
|
|||||||
} else if (precision == 0) {
|
} else if (precision == 0) {
|
||||||
precision = 1;
|
precision = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exp = format_float(convert_float(value), precision, specs,
|
int exp = format_float(convert_float(value), precision, specs,
|
||||||
std::is_same<T, float>(), buffer);
|
std::is_same<T, float>(), buffer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user