Skip to content

Commit 64c83ca

Browse files
authored
Reorganise constants and type aliases (#53)
This new arrangement is more logical and reduces the amount of repetition involved in the definitions.
1 parent 4d3f82c commit 64c83ca

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

src/FixedPoints/SFixed.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,24 @@ template< unsigned Integer, unsigned Fraction >
2626
class SFixed
2727
{
2828
public:
29-
static_assert(((Integer + 1) + Fraction) <= FIXED_POINTS_DETAILS::BitSize<intmax_t>::Value, "Platform does not have a native type large enough for SFixed.");
30-
31-
public:
32-
using IntegerType = FIXED_POINTS_DETAILS::LeastInt<Integer + 1>;
33-
using FractionType = FIXED_POINTS_DETAILS::LeastUInt<Fraction>;
34-
using InternalType = FIXED_POINTS_DETAILS::LeastInt<(Integer + 1) + Fraction>;
35-
36-
using ShiftType = FIXED_POINTS_DETAILS::LeastUInt<(Integer + 1) + Fraction>;
37-
using MaskType = FIXED_POINTS_DETAILS::LeastUInt<(Integer + 1) + Fraction>;
38-
3929
constexpr const static uintmax_t IntegerSize = Integer + 1;
4030
constexpr const static uintmax_t FractionSize = Fraction;
4131
constexpr const static uintmax_t LogicalSize = IntegerSize + FractionSize;
42-
constexpr const static uintmax_t InternalSize = FIXED_POINTS_DETAILS::BitSize<InternalType>::Value;
43-
4432
constexpr const static uintmax_t Scale = UINTMAX_C(1) << FractionSize;
33+
34+
public:
35+
static_assert(LogicalSize <= FIXED_POINTS_DETAILS::BitSize<intmax_t>::Value, "Platform does not have a native type large enough for SFixed.");
36+
37+
public:
38+
using IntegerType = FIXED_POINTS_DETAILS::LeastInt<IntegerSize>;
39+
using FractionType = FIXED_POINTS_DETAILS::LeastUInt<FractionSize>;
40+
using InternalType = FIXED_POINTS_DETAILS::LeastInt<LogicalSize>;
41+
42+
constexpr const static uintmax_t InternalSize = FIXED_POINTS_DETAILS::BitSize<InternalType>::Value;
4543

44+
using ShiftType = FIXED_POINTS_DETAILS::LeastUInt<LogicalSize>;
45+
using MaskType = FIXED_POINTS_DETAILS::LeastUInt<LogicalSize>;
46+
4647
public:
4748
constexpr const static ShiftType IntegerShift = FractionSize;
4849
constexpr const static ShiftType FractionShift = 0;

src/FixedPoints/UFixed.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,24 @@ template< unsigned Integer, unsigned Fraction >
2626
class UFixed
2727
{
2828
public:
29-
static_assert((Integer + Fraction) <= FIXED_POINTS_DETAILS::BitSize<uintmax_t>::Value, "Platform does not have a native type large enough for UFixed.");
30-
31-
public:
32-
using IntegerType = FIXED_POINTS_DETAILS::LeastUInt<Integer>;
33-
using FractionType = FIXED_POINTS_DETAILS::LeastUInt<Fraction>;
34-
using InternalType = FIXED_POINTS_DETAILS::LeastUInt<Integer + Fraction>;
35-
36-
using ShiftType = FIXED_POINTS_DETAILS::LeastUInt<Integer + Fraction>;
37-
using MaskType = FIXED_POINTS_DETAILS::LeastUInt<Integer + Fraction>;
38-
3929
constexpr const static uintmax_t IntegerSize = Integer;
4030
constexpr const static uintmax_t FractionSize = Fraction;
4131
constexpr const static uintmax_t LogicalSize = IntegerSize + FractionSize;
42-
constexpr const static uintmax_t InternalSize = FIXED_POINTS_DETAILS::BitSize<InternalType>::Value;
43-
4432
constexpr const static uintmax_t Scale = UINTMAX_C(1) << FractionSize;
33+
34+
public:
35+
static_assert(LogicalSize <= FIXED_POINTS_DETAILS::BitSize<uintmax_t>::Value, "Platform does not have a native type large enough for UFixed.");
36+
37+
public:
38+
using IntegerType = FIXED_POINTS_DETAILS::LeastUInt<IntegerSize>;
39+
using FractionType = FIXED_POINTS_DETAILS::LeastUInt<FractionSize>;
40+
using InternalType = FIXED_POINTS_DETAILS::LeastUInt<LogicalSize>;
41+
42+
constexpr const static uintmax_t InternalSize = FIXED_POINTS_DETAILS::BitSize<InternalType>::Value;
4543

44+
using ShiftType = FIXED_POINTS_DETAILS::LeastUInt<LogicalSize>;
45+
using MaskType = FIXED_POINTS_DETAILS::LeastUInt<LogicalSize>;
46+
4647
public:
4748
constexpr const static ShiftType IntegerShift = FractionSize;
4849
constexpr const static ShiftType FractionShift = 0;

0 commit comments

Comments
 (0)