From 64c83ca5ce39cd2c1ca50ba8554345fd59afa438 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Thu, 31 May 2018 23:36:28 +0100 Subject: [PATCH] Reorganise constants and type aliases (#53) This new arrangement is more logical and reduces the amount of repetition involved in the definitions. --- src/FixedPoints/SFixed.h | 25 +++++++++++++------------ src/FixedPoints/UFixed.h | 25 +++++++++++++------------ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/FixedPoints/SFixed.h b/src/FixedPoints/SFixed.h index ba5a20a..2890ebf 100644 --- a/src/FixedPoints/SFixed.h +++ b/src/FixedPoints/SFixed.h @@ -26,23 +26,24 @@ template< unsigned Integer, unsigned Fraction > class SFixed { public: - static_assert(((Integer + 1) + Fraction) <= FIXED_POINTS_DETAILS::BitSize::Value, "Platform does not have a native type large enough for SFixed."); - -public: - using IntegerType = FIXED_POINTS_DETAILS::LeastInt; - using FractionType = FIXED_POINTS_DETAILS::LeastUInt; - using InternalType = FIXED_POINTS_DETAILS::LeastInt<(Integer + 1) + Fraction>; - - using ShiftType = FIXED_POINTS_DETAILS::LeastUInt<(Integer + 1) + Fraction>; - using MaskType = FIXED_POINTS_DETAILS::LeastUInt<(Integer + 1) + Fraction>; - constexpr const static uintmax_t IntegerSize = Integer + 1; constexpr const static uintmax_t FractionSize = Fraction; constexpr const static uintmax_t LogicalSize = IntegerSize + FractionSize; - constexpr const static uintmax_t InternalSize = FIXED_POINTS_DETAILS::BitSize::Value; - constexpr const static uintmax_t Scale = UINTMAX_C(1) << FractionSize; + +public: + static_assert(LogicalSize <= FIXED_POINTS_DETAILS::BitSize::Value, "Platform does not have a native type large enough for SFixed."); + +public: + using IntegerType = FIXED_POINTS_DETAILS::LeastInt; + using FractionType = FIXED_POINTS_DETAILS::LeastUInt; + using InternalType = FIXED_POINTS_DETAILS::LeastInt; + + constexpr const static uintmax_t InternalSize = FIXED_POINTS_DETAILS::BitSize::Value; + using ShiftType = FIXED_POINTS_DETAILS::LeastUInt; + using MaskType = FIXED_POINTS_DETAILS::LeastUInt; + public: constexpr const static ShiftType IntegerShift = FractionSize; constexpr const static ShiftType FractionShift = 0; diff --git a/src/FixedPoints/UFixed.h b/src/FixedPoints/UFixed.h index 0fa610c..c5bd163 100644 --- a/src/FixedPoints/UFixed.h +++ b/src/FixedPoints/UFixed.h @@ -26,23 +26,24 @@ template< unsigned Integer, unsigned Fraction > class UFixed { public: - static_assert((Integer + Fraction) <= FIXED_POINTS_DETAILS::BitSize::Value, "Platform does not have a native type large enough for UFixed."); - -public: - using IntegerType = FIXED_POINTS_DETAILS::LeastUInt; - using FractionType = FIXED_POINTS_DETAILS::LeastUInt; - using InternalType = FIXED_POINTS_DETAILS::LeastUInt; - - using ShiftType = FIXED_POINTS_DETAILS::LeastUInt; - using MaskType = FIXED_POINTS_DETAILS::LeastUInt; - constexpr const static uintmax_t IntegerSize = Integer; constexpr const static uintmax_t FractionSize = Fraction; constexpr const static uintmax_t LogicalSize = IntegerSize + FractionSize; - constexpr const static uintmax_t InternalSize = FIXED_POINTS_DETAILS::BitSize::Value; - constexpr const static uintmax_t Scale = UINTMAX_C(1) << FractionSize; + +public: + static_assert(LogicalSize <= FIXED_POINTS_DETAILS::BitSize::Value, "Platform does not have a native type large enough for UFixed."); + +public: + using IntegerType = FIXED_POINTS_DETAILS::LeastUInt; + using FractionType = FIXED_POINTS_DETAILS::LeastUInt; + using InternalType = FIXED_POINTS_DETAILS::LeastUInt; + + constexpr const static uintmax_t InternalSize = FIXED_POINTS_DETAILS::BitSize::Value; + using ShiftType = FIXED_POINTS_DETAILS::LeastUInt; + using MaskType = FIXED_POINTS_DETAILS::LeastUInt; + public: constexpr const static ShiftType IntegerShift = FractionSize; constexpr const static ShiftType FractionShift = 0;