Remove UFixedBase and SFixedBase

pull/46/head
Pharap 6 years ago committed by GitHub
parent ff3308fd96
commit dbb52bf837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/FixedPoints/FixedPoints.h
  2. 40
      src/FixedPoints/SFixed.h
  3. 94
      src/FixedPoints/SFixedMemberFunctions.h
  4. 41
      src/FixedPoints/UFixed.h
  5. 94
      src/FixedPoints/UFixedMemberFunctions.h

@ -14,9 +14,6 @@
#include "Details.h"
#include "UFixedBase.h"
#include "SFixedBase.h"
#include "UFixed.h"
#include "SFixed.h"

@ -15,7 +15,6 @@
#pragma once
#include "Details.h"
#include "SFixedBase.h"
FIXED_POINTS_BEGIN_NAMESPACE
@ -24,7 +23,7 @@ FIXED_POINTS_BEGIN_NAMESPACE
//
template< unsigned Integer, unsigned Fraction >
class SFixed : FIXED_POINTS_DETAILS::SFixedBase< Integer, Fraction >
class SFixed
{
public:
static_assert(((Integer + 1) + Fraction) <= FIXED_POINTS_DETAILS::BitSize<intmax_t>::Value, "Platform does not have a native type large enough for SFixed.");
@ -55,16 +54,41 @@ public:
constexpr const static MaskType MidpointMask = FIXED_POINTS_DETAILS::MsbMask<FractionSize>::Value;
constexpr const static MaskType LesserMidpointMask = MidpointMask - 1;
private:
using Base = FIXED_POINTS_DETAILS::SFixedBase<Integer, Fraction>;
using RawType = typename Base::RawType;
public:
using Base::Base;
protected:
class RawType
{
private:
const InternalType value;
public:
constexpr inline explicit RawType(const InternalType & value) : value(value) {}
constexpr inline explicit operator InternalType(void) const { return this->value; }
};
protected:
InternalType value;
protected:
constexpr SFixed(const RawType & value);
public:
constexpr SFixed(void);
constexpr SFixed(const IntegerType & integer, const FractionType & fraction);
constexpr SFixed(const char & value);
constexpr SFixed(const unsigned char & value);
constexpr SFixed(const signed char & value);
constexpr SFixed(const unsigned short int & value);
constexpr SFixed(const signed short int & value);
constexpr SFixed(const unsigned int & value);
constexpr SFixed(const signed int & value);
constexpr SFixed(const unsigned long int & value);
constexpr SFixed(const signed long int & value);
constexpr SFixed(const unsigned long long int & value);
constexpr SFixed(const signed long long int & value);
constexpr SFixed(const double & value);
constexpr SFixed(const float & value);
constexpr SFixed(const long double & value);
constexpr InternalType getInternal(void) const;
constexpr IntegerType getInteger(void) const;

@ -18,15 +18,105 @@ FIXED_POINTS_BEGIN_NAMESPACE
// Constructors
//
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const RawType & value)
: value(static_cast<InternalType>(value))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(void)
: Base()
: value(0)
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const IntegerType & integer, const FractionType & fraction)
: Base(RawType((static_cast<InternalType>(integer) << FractionSize) | fraction))
: value((static_cast<InternalType>(integer) << FractionSize) | fraction)
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const char & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<char, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned char & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned char, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const signed char & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed char, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned short int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned short int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const signed short int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed short int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const signed int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned long int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned long int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const signed long int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed long int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned long long int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned long long int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const signed long long int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed long long int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const double & value)
: value(static_cast<InternalType>(value * static_cast<double>(Scale)))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const float & value)
: value(static_cast<InternalType>(value * static_cast<float>(Scale)))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::SFixed(const long double & value)
: value(static_cast<InternalType>(value * static_cast<long double>(Scale)))
{
}

@ -15,7 +15,6 @@
#pragma once
#include "Details.h"
#include "UFixedBase.h"
FIXED_POINTS_BEGIN_NAMESPACE
@ -24,7 +23,7 @@ FIXED_POINTS_BEGIN_NAMESPACE
//
template< unsigned Integer, unsigned Fraction >
class UFixed : FIXED_POINTS_DETAILS::UFixedBase< Integer, Fraction >
class UFixed
{
public:
static_assert((Integer + Fraction) <= FIXED_POINTS_DETAILS::BitSize<uintmax_t>::Value, "Platform does not have a native type large enough for UFixed.");
@ -56,16 +55,42 @@ public:
constexpr const static MaskType MidpointMask = FIXED_POINTS_DETAILS::MsbMask<FractionSize>::Value;
constexpr const static MaskType LesserMidpointMask = MidpointMask - 1;
private:
using Base = FIXED_POINTS_DETAILS::UFixedBase<Integer, Fraction>;
using RawType = typename Base::RawType;
protected:
class RawType
{
private:
const InternalType value;
public:
using Base::Base;
public:
constexpr inline explicit RawType(const InternalType & value) : value(value) {}
constexpr inline explicit operator InternalType(void) const { return this->value; }
};
protected:
InternalType value;
protected:
constexpr UFixed(const RawType & value);
public:
constexpr UFixed(void);
constexpr UFixed(const IntegerType & integer, const FractionType & fraction);
constexpr UFixed(const char & value);
constexpr UFixed(const unsigned char & value);
constexpr UFixed(const signed char & value);
constexpr UFixed(const unsigned short int & value);
constexpr UFixed(const signed short int & value);
constexpr UFixed(const unsigned int & value);
constexpr UFixed(const signed int & value);
constexpr UFixed(const unsigned long int & value);
constexpr UFixed(const signed long int & value);
constexpr UFixed(const unsigned long long int & value);
constexpr UFixed(const signed long long int & value);
constexpr UFixed(const double & value);
constexpr UFixed(const float & value);
constexpr UFixed(const long double & value);
public:
constexpr InternalType getInternal(void) const;
constexpr IntegerType getInteger(void) const;
constexpr FractionType getFraction(void) const;

@ -18,15 +18,105 @@ FIXED_POINTS_BEGIN_NAMESPACE
// Constructors
//
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const RawType & value)
: value(static_cast<InternalType>(value))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(void)
: Base()
: value(0)
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const IntegerType & integer, const FractionType & fraction)
: Base(RawType((static_cast<InternalType>(integer) << FractionSize) | fraction))
: value((static_cast<InternalType>(integer) << FractionSize) | fraction)
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const char & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<char, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const unsigned char & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned char, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const signed char & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed char, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const unsigned short int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned short int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const signed short int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed short int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const unsigned int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const signed int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const unsigned long int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned long int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const signed long int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed long int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const unsigned long long int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned long long int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const signed long long int & value)
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed long long int, InternalType> >(value) << FractionSize))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const double & value)
: value(static_cast<InternalType>(value * static_cast<double>(Scale)))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const float & value)
: value(static_cast<InternalType>(value * static_cast<float>(Scale)))
{
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::UFixed(const long double & value)
: value(static_cast<InternalType>(value * static_cast<long double>(Scale)))
{
}

Loading…
Cancel
Save