[clang] [clang] constexpr built-in abs function. (PR #112539)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 17 00:15:23 PDT 2024
================
@@ -265,6 +265,15 @@ namespace fpclassify {
char classify_subnorm [__builtin_fpclassify(-1, -1, -1, +1, -1, 1.0e-38f)];
}
+namespace abs {
+static_assert(__builtin_abs(14) == 14, "");
+static_assert(__builtin_labs(14L) == 14L, "");
+static_assert(__builtin_llabs(14LL) == 14LL, "");
+static_assert(__builtin_abs(-14) == 14, "");
+static_assert(__builtin_labs(-0x14L) == 0x14L, "");
+static_assert(__builtin_llabs(-0x141414141414LL) == 0x141414141414LL, "");
----------------
tbaederr wrote:
```suggestion
static_assert(__builtin_abs(14) == 14, "");
static_assert(__builtin_labs(14L) == 14L, "");
static_assert(__builtin_llabs(14LL) == 14LL, "");
static_assert(__builtin_abs(-14) == 14, "");
static_assert(__builtin_labs(-0x14L) == 0x14L, "");
static_assert(__builtin_llabs(-0x141414141414LL) == 0x141414141414LL, "");
```
https://github.com/llvm/llvm-project/pull/112539
More information about the cfe-commits
mailing list