Your ROOT_URL in app.ini is https://source.parasitstudio.de:63000/ but you are visiting https://source.parasitstudio.de/wirtz/FixedPointsArduino/commit/95dba437d720d6f01ce53733264066a6f18055da?style=split&whitespace=ignore-all
You should set ROOT_URL correctly, otherwise the web may not work correctly.
5 changed files with
53 additions and
5 deletions
README.md
src/FixedPoints/SFixed.h
src/FixedPoints/SFixedMemberFunctions.h
src/FixedPoints/UFixed.h
src/FixedPoints/UFixedMemberFunctions.h
@ -176,11 +176,11 @@ This means that you may write code such as `UFixed<8, 8> value = 0.5;` without i
- `double` .
- `double` .
- The smallest unsigned type capable of holding its integer part. I.e. a type of at least `I` bits.
- The smallest unsigned type capable of holding its integer part. I.e. a type of at least `I` bits.
- Another `UFixed` type of a different scale. E.g. `UFixed<4, 4>` may be converted to `UFixed<8, 8>` and vice versa.
- Another `UFixed` type of a different scale. E.g. `UFixed<4, 4>` may be converted to `UFixed<8, 8>` and vice versa.
- Another `SFixed` type of a different scale. E.g. `UFixed<4, 4>` may be converted to `SFixed<7, 8>` and vice versa.
`SFixed<I, F>` is explicitly convertible to:
`SFixed<I, F>` is explicitly convertible to:
- `float` .
- `float` .
- `double` .
- `double` .
- The smallest signed type capable of holding its integer part. I.e. a type of at least `I + 1` bits.
- The smallest signed type capable of holding its integer part. I.e. a type of at least `I + 1` bits.
- Another `SFixed` type of a different scale. E.g. `SFixed<3, 4>` may be converted to `SFixed<7, 8>` and vice versa.
- Another `SFixed` type of a different scale. E.g. `SFixed<3, 4>` may be converted to `SFixed<7, 8>` and vice versa.
- Another `UFixed` type of a different scale. E.g. `SFixed<3, 4>` may be converted to `UFixed<8, 8>` and vice versa.
@ -22,6 +22,9 @@ FIXED_POINTS_BEGIN_NAMESPACE
// Declaration
// Declaration
//
//
template < unsigned IntegerOut , unsigned FractionOut >
class UFixed ; // forward declaration of UFixed for casting between UFixed and SFixed
template < unsigned Integer , unsigned Fraction >
template < unsigned Integer , unsigned Fraction >
class SFixed
class SFixed
{
{
@ -102,6 +105,8 @@ public:
template < unsigned IntegerOut , unsigned FractionOut >
template < unsigned IntegerOut , unsigned FractionOut >
constexpr explicit operator SFixed < IntegerOut , FractionOut > ( ) const ;
constexpr explicit operator SFixed < IntegerOut , FractionOut > ( ) const ;
template < unsigned IntegerOut , unsigned FractionOut >
constexpr explicit operator UFixed < IntegerOut , FractionOut > ( ) const ;
static constexpr SFixed fromInternal ( const InternalType & value ) ;
static constexpr SFixed fromInternal ( const InternalType & value ) ;
@ -198,6 +198,25 @@ constexpr SFixed<Integer, Fraction>::operator SFixed<IntegerOut, FractionOut>()
OutputType : : fromInternal ( this - > value ) ;
OutputType : : fromInternal ( this - > value ) ;
}
}
template < unsigned Integer , unsigned Fraction >
template < unsigned IntegerOut , unsigned FractionOut >
constexpr SFixed < Integer , Fraction > : : operator UFixed < IntegerOut , FractionOut > ( ) const
{
using OutputType = UFixed < IntegerOut , FractionOut > ;
using OutputInternalType = typename OutputType : : InternalType ;
using OutputShiftType = typename OutputType : : ShiftType ;
using InputType = SFixed < Integer , Fraction > ;
using InputShiftType = typename InputType : : ShiftType ;
return
( FractionOut > FractionSize ) ?
OutputType : : fromInternal ( static_cast < OutputInternalType > ( static_cast < OutputShiftType > ( this - > value ) < < ( ( FractionOut > FractionSize ) ? ( FractionOut - FractionSize ) : 0 ) ) ) :
( FractionSize > FractionOut ) ?
OutputType : : fromInternal ( static_cast < OutputInternalType > ( static_cast < InputShiftType > ( this - > value ) > > ( ( FractionSize > FractionOut ) ? ( FractionSize - FractionOut ) : 0 ) ) ) :
OutputType : : fromInternal ( this - > value ) ;
}
//
//
// Static Functions
// Static Functions
//
//
@ -22,6 +22,9 @@ FIXED_POINTS_BEGIN_NAMESPACE
// Declaration
// Declaration
//
//
template < unsigned IntegerOut , unsigned FractionOut >
class SFixed ; // forward declaration of SFixed for casting between SFixed and UFixed
template < unsigned Integer , unsigned Fraction >
template < unsigned Integer , unsigned Fraction >
class UFixed
class UFixed
{
{
@ -103,6 +106,8 @@ public:
template < unsigned IntegerOut , unsigned FractionOut >
template < unsigned IntegerOut , unsigned FractionOut >
constexpr explicit operator UFixed < IntegerOut , FractionOut > ( ) const ;
constexpr explicit operator UFixed < IntegerOut , FractionOut > ( ) const ;
template < unsigned IntegerOut , unsigned FractionOut >
constexpr explicit operator SFixed < IntegerOut , FractionOut > ( ) const ;
static constexpr UFixed fromInternal ( const InternalType & value ) ;
static constexpr UFixed fromInternal ( const InternalType & value ) ;
@ -189,6 +189,25 @@ constexpr UFixed<Integer, Fraction>::operator UFixed<IntegerOut, FractionOut>()
OutputType : : fromInternal ( this - > value ) ;
OutputType : : fromInternal ( this - > value ) ;
}
}
template < unsigned Integer , unsigned Fraction >
template < unsigned IntegerOut , unsigned FractionOut >
constexpr UFixed < Integer , Fraction > : : operator SFixed < IntegerOut , FractionOut > ( ) const
{
using OutputType = SFixed < IntegerOut , FractionOut > ;
using OutputInternalType = typename OutputType : : InternalType ;
using OutputShiftType = typename OutputType : : ShiftType ;
using InputType = UFixed < Integer , Fraction > ;
using InputShiftType = typename InputType : : ShiftType ;
return
( FractionOut > FractionSize ) ?
OutputType : : fromInternal ( static_cast < OutputInternalType > ( static_cast < OutputShiftType > ( this - > value ) < < ( ( FractionOut > FractionSize ) ? ( FractionOut - FractionSize ) : 0 ) ) ) :
( FractionSize > FractionOut ) ?
OutputType : : fromInternal ( static_cast < OutputInternalType > ( static_cast < InputShiftType > ( this - > value ) > > ( ( FractionSize > FractionOut ) ? ( FractionSize - FractionOut ) : 0 ) ) ) :
OutputType : : fromInternal ( this - > value ) ;
}
//
//
// Static Functions
// Static Functions
//
//