FixMath
|
#include <FixMath.h>
Public Member Functions | |
UFix () | |
UFix (float fl) | |
UFix (double fl) | |
template<typename T > | |
UFix (T value, bool as_raw=false) | |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
UFix (const UFix< _NI, _NF, _RANGE > &uf) | |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
UFix (const SFix< _NI, _NF, _RANGE > &uf) | |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
UFix< FixMathPrivate::neededNIExtra(FixMathPrivate::FM_max(NI, _NI), FixMathPrivate::FM_max(NF, _NF), FixMathPrivate::rangeAdd(NF, _NF, RANGE, _RANGE)), FixMathPrivate::FM_max(NF, _NF), FixMathPrivate::rangeAdd(NF, _NF, RANGE, _RANGE)> | operator+ (const UFix< _NI, _NF, _RANGE > &op) const |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
SFix< FixMathPrivate::neededSNIExtra(FixMathPrivate::FM_max(NI, _NI), FixMathPrivate::FM_max(NF, _NF), FixMathPrivate::rangeAdd(NF, _NF, RANGE, _RANGE)), 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> | |
SFix< FixMathPrivate::FM_max(NI, _NI), FixMathPrivate::FM_max(NF, _NF), FixMathPrivate::FM_max(FixMathPrivate::shiftR(RANGE, FixMathPrivate::FM_max(NF, _NF) -NF), FixMathPrivate::shiftR(_RANGE, FixMathPrivate::FM_max(NF, _NF) -_NF))> | operator- (const UFix< _NI, _NF, _RANGE > &op) const |
SFix< NI, NF, RANGE > | operator- () const |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
UFix< FixMathPrivate::neededNIExtra(NI+_NI, NF+_NF, RANGE *_RANGE), NF+_NF, RANGE *_RANGE > | operator* (const UFix< _NI, _NF, _RANGE > &op) const |
template<int8_t _NI, int8_t _NF, uint64_t _RANGE> | |
SFix< FixMathPrivate::neededSNIExtra(NI+_NI, NF+_NF, RANGE *_RANGE), NF+_NF, RANGE *_RANGE > | operator* (const SFix< _NI, _NF, _RANGE > &op) const |
UFix< NF, NI > | invFast () const |
template<int8_t _NF> | |
UFix< NF, _NF > | inv () const |
UFix< NF, FixMathPrivate::FM_min(NI *2+NF, 63-NF)> | invAccurate () const |
UFix< NI, NF > | operator>> (const int8_t op) const |
template<int8_t op> | |
UFix< FixMathPrivate::FM_max(NI-op, 0), NF+op, FixMathPrivate::rangeShift(NI, op, RANGE)> | sR () |
template<int8_t op> | |
UFix< NI+op, FixMathPrivate::FM_max(NF-op, 0), FixMathPrivate::rangeShift(NF, op, RANGE)> | sL () |
template<int8_t _NI, int8_t _NF> | |
bool | operator> (const UFix< _NI, _NF > &op) const |
template<int8_t _NI, int8_t _NF> | |
bool | operator< (const UFix< _NI, _NF > &op) const |
template<int8_t _NI, int8_t _NF> | |
bool | operator== (const UFix< _NI, _NF > &op) const |
template<int8_t _NI, int8_t _NF> | |
bool | operator!= (const UFix< _NI, _NF > &op) const |
SFix< NI, NF, RANGE > | asSFix () const |
float | asFloat () const |
internal_type | asRaw () const |
int8_t | getNI () const |
int8_t | getNF () const |
Static Public Member Functions | |
template<typename T > | |
static UFix< NI, NF > | fromRaw (T raw) |
Instanciate an unsigned fixed point math number.
NI | The number of bits encoding the integer part. The integral part can range into [0, 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. |
|
inline |
Constructor
|
inline |
Constructor from a positive floating point value.
fl | Floating point value |
|
inline |
Constructor from a floating point value.
fl | Floating point value |
|
inline |
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. |
|
inline |
Constructor from another UFix.
uf | An unsigned fixed type number which value can be represented in this type. |
|
inline |
Constructor from a SFix.
uf | An signed fixed type number which value can be represented in this type: sign is thus discarded. |
|
inline |
Returns the value as floating point number.
|
inline |
Returns the internal integer value
|
inlinestatic |
Set the internal value of the fixed point math number.
raw | The new internal value. |
|
inline |
The number of bits used to encode the fractional part.
|
inline |
The number of bits used to encode the integral part.
|
inline |
Compute the inverse of a UFix<NI,NF>, as a UFix<NF,_NF>. _NF is the number of precision bits for the output. Can be any number but especially useful for case between invFast() (_NF=NI) and invAccurate() (_NF=2*NI+NF)
|
inline |
Compute the inverse of a UFix<NI,NF>, as a UFix<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.
|
inline |
Compute the inverse of a UFix<NI,NF>, as a UFix<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.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Opposite of the number.
|
inline |
|
inline |
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 |
|
inline |
Safe and optimal left shift. The returned type will be adjusted accordingly
op | The shift number |
|
inline |
Safe and optimal right shift. The returned type will be adjusted accordingly
op | The shift number |