diff options
Diffstat (limited to 'compat/limits.hpp')
-rw-r--r-- | compat/limits.hpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/compat/limits.hpp b/compat/limits.hpp index ec1b67a8..0de74afa 100644 --- a/compat/limits.hpp +++ b/compat/limits.hpp @@ -1,3 +1,41 @@ #pragma once -// add things from numeric_limits for {u,}ints and floats/doubles/long doubles +namespace floormat { + +template<typename T> struct limits; + +template<typename T> +requires (std::is_signed_v<T> && std::is_integral_v<T>) +struct limits<T> +{ + using Type = T; + static constexpr T min{-int64_t{1} << sizeof(T)*8-1}, max{-(min+1)}; +}; + +template<typename T> +requires (std::is_unsigned_v<T>) +struct limits<T> +{ + using Type = T; + static_assert(std::is_integral_v<T>); + static constexpr T min{0}, max{T(-1)}; +}; + +template<> struct limits<float> +{ + using Type = float; + static constexpr float max{1 << 24}, min{-max}; + using integer_type = int32_t; +}; + +template<> struct limits<double> +{ + using Type = double; + static constexpr double max = double{uint64_t{1} << 53}, min{-max}; + using integer_type = int64_t; +}; + +template<typename T> requires std::is_arithmetic_v<T> using int_max = typename limits<T>::max;; +template<typename T> requires std::is_arithmetic_v<T> using int_min = typename limits<T>::min;; + +} // namespace floormat |