Skip to content

Commit

Permalink
Remove is_constant_evaluated() check
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
  • Loading branch information
phprus authored and vitaut committed May 24, 2023
1 parent 19b1761 commit 5e988f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
23 changes: 10 additions & 13 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3322,19 +3322,16 @@ template <typename Float> FMT_CONSTEXPR auto iceil(Float value) -> int {
auto max = (std::numeric_limits<int>::max)();
ignore_unused(min, max);
FMT_ASSERT(value >= min && value <= max, "value not in int range");
if (is_constant_evaluated()) {
do {
auto mid = min + static_cast<int>((static_cast<unsigned>(max) -
static_cast<unsigned>(min)) /
2);
if (mid < value)
min = mid;
else
max = mid;
} while (min + 1 != max);
return max;
}
return static_cast<int>(std::ceil(value));
do {
auto mid = min + static_cast<int>((static_cast<unsigned>(max) -
static_cast<unsigned>(min)) /
2);
if (mid < value)
min = mid;
else
max = mid;
} while (min + 1 != max);
return max;
}

template <typename Float>
Expand Down
19 changes: 0 additions & 19 deletions test/format-impl-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,22 +524,6 @@ TEST(format_impl_test, to_utf8) {
EXPECT_EQ(s.size(), u.size());
}

FMT_CONSTEXPR20 bool constexpr_iceil() {
for (double v : std::initializer_list<double>{
((std::numeric_limits<int>::min)() + 0.5),
-1.2,
-0.2,
0.0,
0.2,
1.2,
4.0,
((std::numeric_limits<int>::max)() - 0.5),
}) {
auto r = fmt::detail::iceil(v);
fmt::detail::ignore_unused(r);
}
return true;
}
TEST(format_impl_test, iceil) {
for (double v : std::initializer_list<double>{
((std::numeric_limits<int>::min)() + 0.5),
Expand All @@ -553,7 +537,4 @@ TEST(format_impl_test, iceil) {
}) {
EXPECT_EQ(fmt::detail::iceil(v), static_cast<int>(std::ceil(v)));
}

FMT_CONSTEXPR20 auto result = constexpr_iceil();
EXPECT_TRUE(result);
}

0 comments on commit 5e988f8

Please sign in to comment.