mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-29 13:21:05 +00:00
Move log10_2_significand to format-inl.h
This commit is contained in:
parent
d9ebc4e821
commit
ad77331c04
@ -149,6 +149,9 @@ template <> FMT_FUNC int count_digits<4>(detail::fallback_uintptr n) {
|
||||
return i >= 0 ? i * char_digits + count_digits<4, unsigned>(n.value[i]) : 1;
|
||||
}
|
||||
|
||||
// log10(2) = 0x0.4d104d427de7fbcc...
|
||||
static constexpr uint64_t log10_2_significand = 0x4d104d427de7fbcc;
|
||||
|
||||
#if __cplusplus < 201703L
|
||||
template <typename T> constexpr const char basic_data<T>::digits[][2];
|
||||
template <typename T> constexpr const char basic_data<T>::hex_digits[];
|
||||
@ -326,7 +329,7 @@ inline fp get_cached_power(int min_exponent, int& pow10_exponent) {
|
||||
827, 853, 880, 907, 933, 960, 986, 1013, 1039, 1066};
|
||||
|
||||
const int shift = 32;
|
||||
const auto significand = static_cast<int64_t>(data::log10_2_significand);
|
||||
const auto significand = static_cast<int64_t>(log10_2_significand);
|
||||
int index = static_cast<int>(
|
||||
((min_exponent + fp::significand_size - 1) * (significand >> shift) +
|
||||
((int64_t(1) << shift) - 1)) // ceil
|
||||
@ -913,7 +916,7 @@ inline uint64_t umul96_lower64(uint32_t x, uint64_t y) FMT_NOEXCEPT {
|
||||
inline int floor_log10_pow2(int e) FMT_NOEXCEPT {
|
||||
FMT_ASSERT(e <= 1700 && e >= -1700, "too large exponent");
|
||||
const int shift = 22;
|
||||
return (e * static_cast<int>(data::log10_2_significand >> (64 - shift))) >>
|
||||
return (e * static_cast<int>(log10_2_significand >> (64 - shift))) >>
|
||||
shift;
|
||||
}
|
||||
|
||||
@ -932,7 +935,7 @@ inline int floor_log10_pow2_minus_log10_4_over_3(int e) FMT_NOEXCEPT {
|
||||
FMT_ASSERT(e <= 1700 && e >= -1700, "too large exponent");
|
||||
const uint64_t log10_4_over_3_fractional_digits = 0x1ffbfc2bbc780375;
|
||||
const int shift_amount = 22;
|
||||
return (e * static_cast<int>(data::log10_2_significand >>
|
||||
return (e * static_cast<int>(log10_2_significand >>
|
||||
(64 - shift_amount)) -
|
||||
static_cast<int>(log10_4_over_3_fractional_digits >>
|
||||
(64 - shift_amount))) >>
|
||||
|
@ -885,9 +885,6 @@ using uint64_or_128_t = conditional_t<num_bits<T>() <= 64, uint64_t, uint128_t>;
|
||||
|
||||
// Static data is placed in this class template for the header-only config.
|
||||
template <typename T = void> struct basic_data {
|
||||
// log10(2) = 0x0.4d104d427de7fbcc...
|
||||
static const uint64_t log10_2_significand = 0x4d104d427de7fbcc;
|
||||
|
||||
// GCC generates slightly better code for pairs than chars.
|
||||
FMT_API static constexpr const char digits[100][2] = {
|
||||
{'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, {'0', '5'},
|
||||
|
Loading…
Reference in New Issue
Block a user