[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
Mon Mar 31 12:35:05 PDT 2025


================
@@ -10,18 +10,73 @@
 
 #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)))> {
+struct is_signed : bool_constant<((is_fixed_point_v<T> || is_arithmetic_v<T>) &&
----------------
PiJoules wrote:

Replied to the issue.

tl;dr overflow for non-saturating types isn't defined, so `unsigned _Fract(-1)` can't be constant evaluated. If you want to check if a type is signed, I think you can do `FXRep<T>::MIN() < FXRep::ZERO()`. I also need to update the diagnostic since it's misleading.

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


More information about the libc-commits mailing list