Stop the orgy of casts

This commit is contained in:
Victor Zverovich 2018-12-05 06:27:31 -08:00
parent 37dc495b9d
commit 0497875ff3

View File

@ -539,7 +539,7 @@ FMT_FUNC bool grisu2_gen_digits(
#endif
struct gen_digits_params {
unsigned num_digits;
int num_digits;
bool fixed;
bool upper;
bool trailing_zeros;
@ -617,11 +617,11 @@ struct fill {
// The number is given as v = f * pow(10, exp), where f has size digits.
template <typename Handler>
FMT_FUNC void grisu2_prettify(const gen_digits_params &params,
ptrdiff_t size, int exp, Handler &&handler) {
int size, int exp, Handler &&handler) {
if (!params.fixed) {
// Insert a decimal point after the first digit and add an exponent.
handler.insert(1, '.');
exp += static_cast<int>(size) - 1;
exp += size - 1;
if (size < params.num_digits)
handler.append(params.num_digits - size, '0');
handler.append(params.upper ? 'E' : 'e');
@ -629,13 +629,12 @@ FMT_FUNC void grisu2_prettify(const gen_digits_params &params,
return;
}
// pow(10, full_exp - 1) <= v <= pow(10, full_exp).
int int_size = static_cast<int>(size);
int full_exp = int_size + exp;
int full_exp = size + exp;
const int exp_threshold = 21;
if (int_size <= full_exp && full_exp <= exp_threshold) {
if (size <= full_exp && full_exp <= exp_threshold) {
// 1234e7 -> 12340000000[.0+]
handler.append(full_exp - int_size, '0');
int num_zeros = static_cast<int>(params.num_digits) - full_exp;
handler.append(full_exp - size, '0');
int num_zeros = params.num_digits - full_exp;
if (num_zeros > 0 && params.trailing_zeros) {
handler.append('.');
handler.append(num_zeros, '0');