[clang] [libc] [llvm] [clang] Make __builtin_exp and __builtin_expf constexpr. (PR #199808)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 22 21:57:27 PDT 2026
lntue wrote:
> @lntue, it seems to me that rounding modes other than `FE_TONEAREST`/`FE_DYNAMIC` causes the evaluation to fail; is this expected?:
>
> ```
> $ clang++ -xc++ -<<<'_Pragma("STDC FENV_ROUND FE_TOWARDZERO") constexpr auto x = __builtin_expf(-1.f);'
> <stdin>:1:1: warning: pragma STDC FENV_ROUND is not supported [-Wunknown-pragmas]
> 1 | _Pragma("STDC FENV_ROUND FE_TOWARDZERO") constexpr auto x = __builtin_expf(-1.f);
> | ^
> <scratch space>:4:31: note: expanded from here
> 4 | STDC FENV_ROUND FE_TOWARDZERO
> | ^
> <stdin>:1:57: error: constexpr variable 'x' must be initialized by a constant expression
> 1 | _Pragma("STDC FENV_ROUND FE_TOWARDZERO") constexpr auto x = __builtin_expf(-1.f);
> | ^ ~~~~~~~~~~~~~~~~~~~~
> 1 warning and 1 error generated.
> ```
@hubert-reinterpretcast: it is because of the current limitation I put on `APFloat::exp` since I don't want to mess with the host's floating point environment:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/APFloat.cpp#L6140
We are working on adding static rounding mode math functions that are integer-only without touching the host's floating point environment in LLVM libc, and we will use those to support constant evaluation for other rounding modes. WDYT?
https://github.com/llvm/llvm-project/pull/199808
More information about the cfe-commits
mailing list