[libc-commits] [libc] [libc] Added support for fixed-points in ``is_signed`` and ``is_unsigned``. (PR #133371)
via libc-commits
libc-commits at lists.llvm.org
Fri Mar 28 11:28:20 PDT 2025
================
@@ -8,20 +8,98 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H
+#include "include/llvm-libc-macros/stdfix-macros.h"
#include "src/__support/CPP/type_traits/bool_constant.h"
#include "src/__support/CPP/type_traits/is_arithmetic.h"
+#include "src/__support/CPP/type_traits/is_fixed_point.h"
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
namespace cpp {
-// is_signed
+// Primary template: handles arithmetic and signed fixed-point types
template <typename T>
struct is_signed : bool_constant<(is_arithmetic_v<T> && (T(-1) < T(0)))> {
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
};
----------------
lntue wrote:
So I just tested locally, and the following seems to work without all the specializations:
```
struct is_signed : bool_constant<
(is_fixed_point_v<T> && T(-0.5) < T(0)) ||
(is_arithmetic_v<T> && (T(-1) < T(0)))> {
...
};
```
https://github.com/llvm/llvm-project/pull/133371
More information about the libc-commits
mailing list