[clang] [Clang] Add constexpr eval for cmath builtins (PR #194327)

Serge Pavlov via cfe-commits cfe-commits at lists.llvm.org
Thu May 7 23:53:23 PDT 2026


================
@@ -0,0 +1,270 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify -std=c++20 %s
+// RUN: %clang_cc1 -verify -std=c++20 %s
+
+
+
+static_assert(__builtin_nearbyint(1.1) == 1.0);
+static_assert(__builtin_nearbyint(1.9) == 2.0);
+static_assert(__builtin_nearbyint(-1.1) == -1.0);
+static_assert(__builtin_nearbyint(-1.9) == -2.0);
+
+static_assert(__builtin_nearbyintf(1.1f) == 1.0f);
----------------
spavloff wrote:

Functions that depend on rounding mode. like `nearbyint`, should be tested with statis rounding mode. `#pragma STDC FENV_ROUND` may be used to set the mode. Although clang warns that the pragma is unsupported, it must correctly assign FPOptions in AST.


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


More information about the cfe-commits mailing list