Refer to jeaiii project

This commit is contained in:
Victor Zverovich 2017-12-10 16:09:35 -08:00
parent e37151021e
commit ccaae0c019

View File

@ -797,6 +797,8 @@ class decimal_formatter {
} else if (N == 1) { } else if (N == 1) {
write_pair(0, u); write_pair(0, u);
} else { } else {
// The idea of using 4.32 fixed-point numbers is based on
// https://github.com/jeaiii/itoa
unsigned n = N - 1; unsigned n = N - 1;
unsigned a = n / 5 * n * 53 / 16; unsigned a = n / 5 * n * 53 / 16;
uint64_t t = ((1ULL << (32 + a)) / data::POWERS_OF_10_32[n] + 1 - n / 9); uint64_t t = ((1ULL << (32 + a)) / data::POWERS_OF_10_32[n] + 1 - n / 9);