[libc-commits] [libc] [libc] Make FPUtils' rounding_mode.h functions constexpr. (PR #149167)
via libc-commits
libc-commits at lists.llvm.org
Wed Jul 23 07:18:25 PDT 2025
================
@@ -20,18 +21,26 @@ namespace fputil {
// Using the following observation:
// 1.0f + 2^-25 = 1.0f for FE_TONEAREST, FE_DOWNWARD, FE_TOWARDZERO
// = 0x1.000002f for FE_UPWARD.
-LIBC_INLINE bool fenv_is_round_up() {
- volatile float x = 0x1.0p-25f;
- return (1.0f + x != 1.0f);
+LIBC_INLINE static constexpr bool fenv_is_round_up() {
+ if (cpp::is_constant_evaluated()) {
+ return false;
+ } else {
----------------
overmighty wrote:
Nit: if `if constexpr` is not needed then the `else` after `return` should be removed as per the LLVM Coding Standards. Same for the other functions changed.
https://github.com/llvm/llvm-project/pull/149167
More information about the libc-commits
mailing list