mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-14 18:40:44 +00:00
Apply get_cached_power optimization by jk-jeon
This commit is contained in:
parent
8e700619b7
commit
791294d17b
@ -480,9 +480,14 @@ FMT_FUNC fp operator*(fp x, fp y) {
|
|||||||
// Returns a cached power of 10 `c_k = c_k.f * pow(2, c_k.e)` such that its
|
// Returns a cached power of 10 `c_k = c_k.f * pow(2, c_k.e)` such that its
|
||||||
// (binary) exponent satisfies `min_exponent <= c_k.e <= min_exponent + 28`.
|
// (binary) exponent satisfies `min_exponent <= c_k.e <= min_exponent + 28`.
|
||||||
FMT_FUNC fp get_cached_power(int min_exponent, int& pow10_exponent) {
|
FMT_FUNC fp get_cached_power(int min_exponent, int& pow10_exponent) {
|
||||||
const double one_over_log2_10 = 0.30102999566398114; // 1 / log2(10)
|
const uint64_t one_over_log2_10 = 0x4d104d42; // round(pow(2, 32) / log2(10))
|
||||||
int index = static_cast<int>(
|
int index = static_cast<int>(
|
||||||
std::ceil((min_exponent + fp::significand_size - 1) * one_over_log2_10));
|
static_cast<int64_t>(
|
||||||
|
(min_exponent + fp::significand_size - 1) * one_over_log2_10 +
|
||||||
|
((uint64_t(1) << 32) - 1) // ceil
|
||||||
|
) >>
|
||||||
|
32 // arithmetic shift
|
||||||
|
);
|
||||||
// Decimal exponent of the first (smallest) cached power of 10.
|
// Decimal exponent of the first (smallest) cached power of 10.
|
||||||
const int first_dec_exp = -348;
|
const int first_dec_exp = -348;
|
||||||
// Difference between 2 consecutive decimal exponents in cached powers of 10.
|
// Difference between 2 consecutive decimal exponents in cached powers of 10.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user