[libc-commits] [libc] [llvm] [libc] Add the digit property to numeric_limits (PR #73926)

Clement Courbet via libc-commits libc-commits at lists.llvm.org
Thu Nov 30 04:00:22 PST 2023


================
@@ -24,77 +25,72 @@ constexpr long long LLONG_MIN = 1LL << (LLONG_BIT_WIDTH - 1);
 constexpr unsigned long long ULLONG_MAX = ~0ULL;
 #endif
 
-template <class T> class numeric_limits {
-public:
-  LIBC_INLINE static constexpr T max();
-  LIBC_INLINE static constexpr T min();
+namespace internal {
+
+template <typename T, T min_value, T max_value> struct numeric_limits_impl {
+  LIBC_INLINE static constexpr T max() { return max_value; }
+  LIBC_INLINE static constexpr T min() { return min_value; }
+  LIBC_INLINE_VAR static constexpr int digits =
+      CHAR_BIT * sizeof(T) - cpp::is_signed_v<T>;
----------------
legrosbuffle wrote:

Maybe add a `static_assert(is_integral<T>)` in case someone tries to use this for `float` ?

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


More information about the libc-commits mailing list