[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 20:50:39 PDT 2024
================
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \
+// RUN: -DWIN -emit-llvm -o - %s | FileCheck %s --check-prefixes=WIN
+
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -std=c++23 \
+// RUN: -emit-llvm -o - %s | FileCheck %s --check-prefixes=LNX
+
+#ifdef WIN
+#define INFINITY ((float)(1e+300 * 1e+300))
+#define NAN (-(float)(INFINITY * 0.0F))
+#else
+#define NAN (__builtin_nanf(""))
+#define INFINITY (__builtin_inff())
+#endif
+
+int func()
+{
+ int i;
+
+ // fmin
+ constexpr double f1 = __builtin_fmin(15.24, 1.3);
+ constexpr double f2 = __builtin_fmin(-0.0, +0.0);
+ constexpr double f3 = __builtin_fmin(+0.0, -0.0);
+ constexpr float f4 = __builtin_fminf(NAN, NAN);
+ constexpr float f5 = __builtin_fminf(NAN, -1);
+ constexpr float f6 = __builtin_fminf(-INFINITY, 0);
+ constexpr float f7 = __builtin_fminf(INFINITY, 0);
+ constexpr long double f8 = __builtin_fminl(123.456L, 789.012L);
+
+ // frexp
+ constexpr double f9 = __builtin_frexp(123.45, &i);
+ constexpr double f10 = __builtin_frexp(0.0, &i);
+ constexpr double f11 = __builtin_frexp(-0.0, &i);
+ constexpr double f12 = __builtin_frexpf(NAN, &i);
+ constexpr double f13 = __builtin_frexpf(-NAN, &i);
+ constexpr double f14 = __builtin_frexpf(INFINITY, &i);
----------------
hubert-reinterpretcast wrote:
Copy/paste errors?
```suggestion
constexpr float f12 = __builtin_frexpf(NAN, &i);
constexpr float f13 = __builtin_frexpf(-NAN, &i);
constexpr float f14 = __builtin_frexpf(INFINITY, &i);
```
https://github.com/llvm/llvm-project/pull/88978
More information about the cfe-commits
mailing list