Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jk-jeon authored Sep 22, 2020
1 parent bb0db5e commit 6bcde9a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions test/grisu-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)); }
Expand Down

0 comments on commit 6bcde9a

Please sign in to comment.