Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make constexpr ceil #3459

Merged
merged 3 commits into from
May 24, 2023
Merged

Make constexpr ceil #3459

merged 3 commits into from
May 24, 2023

Conversation

phprus
Copy link
Contributor

@phprus phprus commented May 23, 2023

Fix for 858e528#r114625556

Broken on macOS 13.3.1
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
C++20.

/.../fmt/test/compile-fp-test.cc:32: error: call to consteval function 'test_format<11UL, char, float, FMT_COMPILE_STRING>' is not a constant expression
/.../fmt/test/compile-fp-test.cc:32:27: error: call to consteval function 'test_format<11UL, char, float, FMT_COMPILE_STRING>' is not a constant expression
  EXPECT_EQ("392.500000", test_format<11>(FMT_COMPILE("{0:f}"), 392.5f));
                          ^
/.../fmt/include/fmt/format.h:3351:9: note: non-constexpr function 'ceil' cannot be used in a constant expression
        std::ceil((f.e + count_digits<1>(f.f) - 1) * inv_log2_10 - 1e-10));

std::ceil is constexpr since C++23 (https://en.cppreference.com/w/cpp/numeric/math/ceil)

This is not a compiler bug. This is unimplemented feature in clang and msvs. Only gcc support it.
https://en.cppreference.com/w/cpp/compiler_support

@phprus phprus marked this pull request as draft May 23, 2023 20:01
@phprus phprus force-pushed the constexpr-math-1 branch from a09d23d to 7d3092e Compare May 23, 2023 20:09
@phprus phprus marked this pull request as ready for review May 23, 2023 20:19
Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/format.h Outdated Show resolved Hide resolved
Signed-off-by: Vladislav Shchapov <[email protected]>
@phprus phprus force-pushed the constexpr-math-1 branch from 7d3092e to d719460 Compare May 24, 2023 14:49
@phprus
Copy link
Contributor Author

phprus commented May 24, 2023

@vitaut
Done.

Signed-off-by: Vladislav Shchapov <[email protected]>
@phprus phprus force-pushed the constexpr-math-1 branch from d719460 to 8bdd1f6 Compare May 24, 2023 14:58
include/fmt/format.h Outdated Show resolved Hide resolved
test/format-impl-test.cc Outdated Show resolved Hide resolved
Signed-off-by: Vladislav Shchapov <[email protected]>
@vitaut vitaut merged commit 5e988f8 into fmtlib:master May 24, 2023
@vitaut
Copy link
Contributor

vitaut commented May 24, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants