jk-jeon 2020-09-22 10:33:52 -07:00 committed by GitHub
parent bb0db5e51e
commit 6bcde9aab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -1990,17 +1990,17 @@ template <int N> struct small_division_by_pow10_info;
template <> struct small_division_by_pow10_info<1> {
static const uint32_t magic_number = 0xcccd;
static const int shift_amount = 19;
static const int divisor = 10;
static const int divisor_times_10 = 100;
};
template <> struct small_division_by_pow10_info<2> {
static const uint32_t magic_number = 0xa3d8;
static const int shift_amount = 22;
static const int divisor = 100;
static const int divisor_times_10 = 1000;
};
template <int N> uint32_t small_division_by_pow10(uint32_t n) FMT_NOEXCEPT {
FMT_ASSERT(n <= small_division_by_pow10_info<N>::divisor, "n is too large");
FMT_ASSERT(n <= small_division_by_pow10_info<N>::divisor_times_10, "n is too large");
return (n * small_division_by_pow10_info<N>::magic_number) >>
small_division_by_pow10_info<N>::shift_amount;
}

View File

@ -54,6 +54,7 @@ TEST(GrisuTest, Prettify) {
EXPECT_EQ("0.001234", fmt::format("{}", 1234e-6));
EXPECT_EQ("0.1", fmt::format("{}", 0.1f));
EXPECT_EQ("0.10000000149011612", fmt::format("{}", double(0.1f)));
EXPECT_EQ("1.3563156e-19", fmt::format("{}", 1.35631564e-19f));
}
TEST(GrisuTest, ZeroPrecision) { EXPECT_EQ("1", fmt::format("{:.0}", 1.0)); }