FixMath
|
#include <FixMath.h>
Public Member Functions | |
constexpr | SFix () |
constexpr | SFix (float fl) |
constexpr | SFix (double fl) |
template<typename T > | |
constexpr | SFix (T value, bool as_raw=false) |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
constexpr | SFix (const SFix< _NI, _NF, _RANGE > &sf) |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
constexpr | SFix (const UFix< _NI, _NF, _RANGE > &uf) |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
constexpr FixMathPrivate::SFixByRange_t< FixMathPrivate::FM_max(NF, _NF), FixMathPrivate::rangeAdd(NF, _NF, RANGE, _RANGE)> | operator+ (const SFix< _NI, _NF, _RANGE > &op) const |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
constexpr FixMathPrivate::SFixByRange_t< FixMathPrivate::FM_max(NF, _NF), FixMathPrivate::rangeAdd(NF, _NF, RANGE, _RANGE)> | operator+ (const UFix< _NI, _NF, _RANGE > &op2) const |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
constexpr FixMathPrivate::SFixByRange_t< FixMathPrivate::FM_max(NF, _NF), FixMathPrivate::rangeAdd(NF, _NF, RANGE, _RANGE)> | operator- (const SFix< _NI, _NF, _RANGE > &op) const |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
constexpr FixMathPrivate::SFixByRange_t< FixMathPrivate::FM_max(NF, _NF), FixMathPrivate::rangeAdd(NF, _NF, RANGE, _RANGE)> | operator- (const UFix< _NI, _NF, _RANGE > &op) const |
constexpr FixMathPrivate::SFixByRange_t< NF, RANGE+1 > | operator- () const |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
constexpr FixMathPrivate::SFixByRange_t< NF+_NF, RANGE *_RANGE > | operator* (const SFix< _NI, _NF, _RANGE > &op) const |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
constexpr FixMathPrivate::SFixByRange_t< NF+_NF, RANGE *_RANGE > | operator* (const UFix< _NI, _NF, _RANGE > &op2) const |
constexpr SFix< NF, NI > | invFast () const |
template<int8_t _NF> | |
constexpr SFix< NF, _NF > | inv () const |
constexpr SFix< NF, FixMathPrivate::FM_min(NI *2+NF, 63-NF)> | invFull () const |
template<int8_t _NF = FixMathPrivate::FM_min(NI*2+NF-1,63-NF)> | |
constexpr SFix< NF, _NF > | invAccurate () const |
constexpr SFix< NI, NF > | operator>> (const int8_t op) const |
template<int8_t op> | |
constexpr SFix< FixMathPrivate::FM_max(NI-op, 0), NF+op, FixMathPrivate::rangeShift(NI, op, RANGE)> | sR () |
template<int8_t op> | |
constexpr SFix< NI+op, FixMathPrivate::FM_max(NF-op, 0), FixMathPrivate::rangeShift(NF, op, RANGE)> | sL () |
template<int8_t _NI, int8_t _NF> | |
constexpr bool | operator> (const SFix< _NI, _NF > &op) const |
template<int8_t _NI, int8_t _NF> | |
constexpr bool | operator< (const SFix< _NI, _NF > &op) const |
template<int8_t _NI, int8_t _NF> | |
constexpr bool | operator== (const SFix< _NI, _NF > &op) const |
template<int8_t _NI, int8_t _NF> | |
constexpr bool | operator!= (const SFix< _NI, _NF > &op) const |
constexpr UFix< NI, NF, RANGE > | asUFix () const |
constexpr float | asFloat () const |
constexpr IntegerType< FixMathPrivate::sBitsToBytes(NI+1)>::signed_type | asInt () const |
constexpr internal_type | asRaw () const |
Static Public Member Functions | |
template<typename T > | |
static constexpr SFix< NI, NF > | fromRaw (T raw) |
static constexpr int8_t | getNI () |
static constexpr int8_t | getNF () |
static constexpr int8_t | getRANGE () |
template<int8_t BITS> | |
static constexpr void | assertSize () |
Friends | |
template<int8_t , int8_t , uint64_t > | |
class | UFix |
Instanciate an signed fixed point math number.
NI | The number of bits encoding the integer part. The integral part can range into [-2^NI, 2^NI -1] |
NF | The number of bits encoding the fractional part |
RANGE | A purely internal parameter that keeps track of the range used by the type. Safer to not define it. |
|
inlineconstexpr |
Constructor
|
inlineconstexpr |
Constructor from a floating point value.
fl | Floating point value |
|
inlineconstexpr |
Constructor from a floating point value.
fl | Floating point value |
|
inlineconstexpr |
Constructor from an integer value which can be interpreted as both a resulting fixed point math number with a fractional part equals to 0, or as a number with decimal, ie as the underlying type behind the fixed point math number.
value | Integer value |
as_raw=false | with false value will be interpreted as an integer, with true it will be interpreted as a number with decimals. |
|
inlineconstexpr |
Constructor from another SFix.
uf | A signed fixed type number which value can be represented in this type. |
|
inlineconstexpr |
Constructor from an UFix.
uf | A unsigned fixed type number which value can be represented in this type. |
|
inlineconstexpr |
Returns the value as floating point number.
|
inlineconstexpr |
Return the integer part of the number, as a standard C type integer (int8_t, int16_t etc) depending on NI.
|
inlineconstexpr |
Returns the internal integer value
|
inlinestaticconstexpr |
Check wether this number exceeds the given total size in bits. See UFix::assertSize().
|
inlinestaticconstexpr |
Set the internal value of the fixed point math number.
raw | The new internal value. |
|
inlinestaticconstexpr |
The number of bits used to encode the fractional part.
|
inlinestaticconstexpr |
The number of bits used to encode the integral part.
|
inlinestaticconstexpr |
The (absolute) range of the integral part of the number, as far as it can be determined at compile time. The true range of the number will typically be lower than (at most the same as) this, so it is not recommended to use this in computations. Available with #define FIXMATH_DEBUG
|
inlineconstexpr |
Compute the inverse of a SFix<NI,NF>, as a SFix<NF,NI*2+NF-1> (default) or as a SFix<NF,_NF> with _NF the template parameter of invAccurate<_NF>.
|
inlineconstexpr |
Compute the inverse of a SFix<NI,NF>, as a SFix<NF,NI> (not a typo). This inverse is able to represent accurately the inverse of the smallest and biggest of the initial number, but might lead to a lot of duplicates in between. Good if precision is not a premium but type conservation and speeds are. This is still slower than a multiplication, hence the suggested workflow is to compute the inverse when time is not critical, for instance in updateControl(), and multiply it afterward, for instance in updateAudio(), if you need a division.
|
inlineconstexpr |
Compute the inverse of a SFix<NI,NF>, as a SFix<NF,NI*2+NF>. This inverse is more accurate than invFast, and usually leads to non common values on the whole input range. This comes at the cost of a way bigger resulting type. This is still slower than a multiplication, hence the suggested workflow is to compute the inverse when time is not critical, for instance in updateControl(), and multiply it afterward, for instance in updateAudio(), if you need a division.
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
Opposite of the number (unary minus operator).
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
Right shift. This won't overflow but will not leverage on the bits freed by the shift. Better to use .sR<shift>() if possible instead.
op | The shift number |
|
inlineconstexpr |
Safe and optimal left shift. The returned type will be adjusted accordingly
op | The shift number |
|
inlineconstexpr |
Safe and optimal right shift. The returned type will be adjusted accordingly
op | The shift number |