Add cached powers of 10

This commit is contained in:
Victor Zverovich
2018-04-29 06:33:05 -07:00
parent dd296e1de0
commit 2768af2388
3 changed files with 92 additions and 7 deletions
+5 -3
View File
@@ -263,10 +263,10 @@ inline fp operator-(fp x, fp y) {
fp operator*(fp x, fp y);
// Compute k such that its cached power c_k = c_k.f * pow(2, c_k.e) satisfies
// alpha <= c_k.e + e <= alpha + 3.
inline int compute_cached_power_index(int e, int alpha) {
// min_exponent <= c_k.e + e <= min_exponent + 3.
inline int compute_cached_power_index(int e, int min_exponent) {
constexpr double one_over_log2_10 = 0.30102999566398114; // 1 / log2(10)
return static_cast<int>(std::ceil((alpha - e + 63) * one_over_log2_10));
return static_cast<int>(std::ceil((min_exponent - e + 63) * one_over_log2_10));
}
template <typename Allocator>
@@ -795,6 +795,8 @@ template <typename T = void>
struct FMT_API basic_data {
static const uint32_t POWERS_OF_10_32[];
static const uint64_t POWERS_OF_10_64[];
static const uint64_t POW10_SIGNIFICANDS[];
static const int16_t POW10_EXPONENTS[];
static const char DIGITS[];
};