Add integer conversion operators (#94)

Adds operators for converting to all the main integer types.
pull/97/head
Pharap 4 years ago committed by GitHub
parent ea71949e81
commit 5eadcbadf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/FixedPoints/SFixed.h
  2. 64
      src/FixedPoints/SFixedMemberFunctions.h
  3. 13
      src/FixedPoints/UFixed.h
  4. 64
      src/FixedPoints/UFixedMemberFunctions.h

@ -98,7 +98,18 @@ public:
constexpr IntegerType getInteger() const;
constexpr FractionType getFraction() const;
constexpr explicit operator IntegerType() const;
constexpr explicit operator char() const;
constexpr explicit operator unsigned char() const;
constexpr explicit operator signed char() const;
constexpr explicit operator unsigned short int() const;
constexpr explicit operator signed short int() const;
constexpr explicit operator unsigned int() const;
constexpr explicit operator signed int() const;
constexpr explicit operator unsigned long int() const;
constexpr explicit operator signed long int() const;
constexpr explicit operator unsigned long long int() const;
constexpr explicit operator signed long long int() const;
constexpr explicit operator float() const;
constexpr explicit operator double() const;
constexpr explicit operator long double() const;

@ -147,11 +147,73 @@ constexpr typename SFixed<Integer, Fraction>::FractionType SFixed<Integer, Fract
//
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator IntegerType() const
constexpr SFixed<Integer, Fraction>::operator char() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator unsigned char() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator signed char() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator unsigned short int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator signed short int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator unsigned int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator signed int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator unsigned long int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator signed long int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator unsigned long long int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator signed long long int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator float() const
{

@ -99,7 +99,18 @@ public:
constexpr IntegerType getInteger() const;
constexpr FractionType getFraction() const;
constexpr explicit operator IntegerType() const;
constexpr explicit operator char() const;
constexpr explicit operator unsigned char() const;
constexpr explicit operator signed char() const;
constexpr explicit operator unsigned short int() const;
constexpr explicit operator signed short int() const;
constexpr explicit operator unsigned int() const;
constexpr explicit operator signed int() const;
constexpr explicit operator unsigned long int() const;
constexpr explicit operator signed long int() const;
constexpr explicit operator unsigned long long int() const;
constexpr explicit operator signed long long int() const;
constexpr explicit operator float() const;
constexpr explicit operator double() const;
constexpr explicit operator long double() const;

@ -147,11 +147,73 @@ constexpr typename UFixed<Integer, Fraction>::FractionType UFixed<Integer, Fract
//
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator IntegerType() const
constexpr UFixed<Integer, Fraction>::operator char() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator unsigned char() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator signed char() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator unsigned short int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator signed short int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator unsigned int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator signed int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator unsigned long int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator signed long int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator unsigned long long int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator signed long long int() const
{
return this->getInteger();
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator float() const
{

Loading…
Cancel
Save