/* Type limits for OctaSTD. * * This file is part of OctaSTD. See COPYING.md for futher information. */ #ifndef OSTD_LIMITS_HH #define OSTD_LIMITS_HH #include #include #include "ostd/types.hh" #include "ostd/type_traits.hh" namespace ostd { namespace detail { template, bool F = IsFloatingPoint> struct NumericLimitsBase { static constexpr T minv = T{}; static constexpr T maxv = T{}; static constexpr T lowv = T{}; static constexpr bool is_signed = false; static constexpr bool is_integer = false; }; /* signed integer types */ template> struct IntegerLimitsBase { using UT = MakeUnsigned; static constexpr T minv = -(~(1ULL << (sizeof(T) * CHAR_BIT - 1))) - 1; static constexpr T maxv = T(UT(~UT(0)) >> 1); static constexpr T lowv = minv; static constexpr bool is_signed = true; static constexpr bool is_integer = true; }; /* unsigned integer types */ template struct IntegerLimitsBase { static constexpr T minv = T(0); static constexpr T maxv = ~T(0); static constexpr T lowv = minv; static constexpr bool is_signed = false; static constexpr bool is_integer = true; }; /* all integer types */ template struct NumericLimitsBase: IntegerLimitsBase {}; /* floating point types */ template struct FloatLimitsBase; template<> struct FloatLimitsBase { static constexpr float minv = FLT_MIN; static constexpr float maxv = FLT_MAX; static constexpr float lowv = -maxv; }; template<> struct FloatLimitsBase { static constexpr double minv = DBL_MIN; static constexpr double maxv = DBL_MAX; static constexpr double lowv = -maxv; }; template<> struct FloatLimitsBase { static constexpr long double minv = LDBL_MIN; static constexpr long double maxv = LDBL_MAX; static constexpr long double lowv = -maxv; }; template struct NumericLimitsBase: FloatLimitsBase { static constexpr bool is_signed = true; static constexpr bool is_integer = false; }; } template constexpr T NumericLimitMin = detail::NumericLimitsBase::minv; template constexpr T NumericLimitMax = detail::NumericLimitsBase::maxv; template constexpr T NumericLimitLowest = detail::NumericLimitsBase::lowv; template constexpr bool NumericLimitIsSigned = detail::NumericLimitsBase::is_signed; template constexpr bool NumericLimitIsInteger = detail::NumericLimitsBase::is_integer; } #endif