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

Hubert Tong via cfe-commits cfe-commits at lists.llvm.org
Sat May 4 18:59:49 PDT 2024


================
@@ -14547,6 +14547,20 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
   default:
     return false;
 
+  case Builtin::BI__builtin_frexp:
+  case Builtin::BI__builtin_frexpf:
+  case Builtin::BI__builtin_frexpl: {
+    LValue Pointer;
+    if (!EvaluateFloat(E->getArg(0), Result, Info) ||
+        !EvaluatePointer(E->getArg(1), Pointer, Info))
+      return false;
+    llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
+    int FrexpExp;
+    FrexpExp = ilogb(Result);
+    FrexpExp = FrexpExp == llvm::detail::IEEEFloat::IEK_Zero ? 0 : FrexpExp + 1;
+    Result =  scalbn(Result, -FrexpExp, RM);
----------------
hubert-reinterpretcast wrote:

This is not an improvement over
https://github.com/llvm/llvm-project/blob/d7050b53a75a23024502a9e4f56b385256c4722f/clang/lib/AST/ExprConstant.cpp#L14558

It is still the case that no attempt is made to store the value of `FrexpExp` via `Pointer`.

Additionally, (although potentially "better" than the status quo of `llvm::frexp`) this adds yet another place where the calculation for IBM double-double would potentially need special maintenance. See https://github.com/llvm/llvm-project/issues/90287.


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


More information about the cfe-commits mailing list