diff --git a/include/fmt/format.h b/include/fmt/format.h index d4951cb5..aae28016 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3317,23 +3317,6 @@ FMT_CONSTEXPR20 void format_hexfloat(Float value, int precision, format_hexfloat(static_cast(value), precision, specs, buf); } -template FMT_CONSTEXPR auto iceil(Float value) -> int { - auto min = (std::numeric_limits::min)(); - auto max = (std::numeric_limits::max)(); - ignore_unused(min, max); - FMT_ASSERT(value >= min && value <= max, "value not in int range"); - do { - auto mid = min + static_cast((static_cast(max) - - static_cast(min)) / - 2); - if (mid < value) - min = mid; - else - max = mid; - } while (min + 1 != max); - return max; -} - template FMT_CONSTEXPR20 auto format_float(Float value, int precision, float_specs specs, buffer& buf) -> int { @@ -3364,7 +3347,9 @@ FMT_CONSTEXPR20 auto format_float(Float value, int precision, float_specs specs, // 10^(exp - 1) <= value < 10^exp or 10^exp <= value < 10^(exp + 1). // This is based on log10(value) == log2(value) / log2(10) and approximation // of log2(value) by e + num_fraction_bits idea from double-conversion. - exp = iceil((f.e + count_digits<1>(f.f) - 1) * inv_log2_10 - 1e-10); + auto e = (f.e + count_digits<1>(f.f) - 1) * inv_log2_10 - 1e-10; + exp = static_cast(e); + if (e > exp) ++exp; // Compute ceil. dragon_flags = dragon::fixup; } else if (precision < 0) { // Use Dragonbox for the shortest format. diff --git a/test/compile-fp-test.cc b/test/compile-fp-test.cc index b93e46e3..5b46d74b 100644 --- a/test/compile-fp-test.cc +++ b/test/compile-fp-test.cc @@ -10,7 +10,7 @@ #if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806 && \ defined(__cpp_constexpr) && __cpp_constexpr >= 201907 && \ - defined(__cpp_constexpr_dynamic_alloc) && !FMT_MSC_VERSION && \ + defined(__cpp_constexpr_dynamic_alloc) && \ __cpp_constexpr_dynamic_alloc >= 201907 && FMT_CPLUSPLUS >= 202002L template struct test_string { diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index cdd34164..35e9d568 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -523,18 +523,3 @@ TEST(format_impl_test, to_utf8) { EXPECT_EQ(s, u.str()); EXPECT_EQ(s.size(), u.size()); } - -TEST(format_impl_test, iceil) { - for (double v : std::initializer_list{ - ((std::numeric_limits::min)() + 0.5), - -1.2, - -0.2, - 0.0, - 0.2, - 1.2, - 4.0, - ((std::numeric_limits::max)() - 0.5), - }) { - EXPECT_EQ(fmt::detail::iceil(v), static_cast(std::ceil(v))); - } -}