[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

Zahira Ammarguellat via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 14:43:13 PDT 2024


================
@@ -2922,7 +2922,7 @@ static bool handleFloatFloatBinOp(EvalInfo &Info, const BinaryOperator *E,
   //   If during the evaluation of an expression, the result is not
   //   mathematically defined [...], the behavior is undefined.
   // FIXME: C++ rules require us to not conform to IEEE 754 here.
-  if (LHS.isNaN()) {
+  if (!Info.getLangOpts().CPlusPlus23 && LHS.isNaN()) {
----------------
zahiraam wrote:

> My understanding of the intended design was that operations producing NaNs from non-NaNs in C++ constexpr cause the expression to not be constant. That said, NaNs are still in play because of `numeric_limits`.
> 
> For `frexp` though, I think there being an "unspecified" value stored for the exponent is a problem where the design could use more clarity. I would think that the operation could still be performed, but the "unspecified" value should probably be considered indeterminate.

For C it looks like it's returning INT_MAX and INT__MIN. See comment/code here:
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/APFloat.h#L1371

Do we want to do the same for C++23? If not what's exactly an "unspecified" value? 

https://github.com/llvm/llvm-project/pull/88978


More information about the cfe-commits mailing list