openMSX
|
A fixed point number, implemented by a 32-bit signed integer. More...
#include <FixedPoint.hh>
Public Member Functions | |
constexpr | FixedPoint ()=default |
Creates a zero-initialized fixed point object. More... | |
constexpr | FixedPoint (int i) |
constexpr | FixedPoint (unsigned i) |
FixedPoint (float f) | |
FixedPoint (double d) | |
template<unsigned BITS2> | |
constexpr | FixedPoint (FixedPoint< BITS2 > other) |
constexpr int | toInt () const |
Returns the integer part (rounded down) of this fixed point number. More... | |
constexpr float | toFloat () const |
Returns the float value that corresponds to this fixed point number. More... | |
constexpr double | toDouble () const |
Returns the double value that corresponds to this fixed point number. More... | |
constexpr float | fractionAsFloat () const |
Returns the fractional part of this fixed point number as a float. More... | |
constexpr double | fractionAsDouble () const |
Returns the fractional part of this fixed point number as a double. More... | |
constexpr int | divAsInt (FixedPoint other) const |
Returns the result of a division between this fixed point number and another, rounded towards zero. More... | |
constexpr FixedPoint | floor () const |
Returns this value rounded down. More... | |
constexpr FixedPoint | fract () const |
Returns the fractional part of this value. More... | |
constexpr unsigned | fractAsInt () const |
Returns the fractional part of this value as an integer. More... | |
constexpr void | operator+= (FixedPoint other) |
constexpr void | operator-= (FixedPoint other) |
constexpr void | addQuantum () |
Increase this value with the smallest possible amount. More... | |
constexpr int | getRawValue () const |
template<typename Archive > | |
void | serialize (Archive &ar, unsigned) |
Static Public Member Functions | |
static constexpr FixedPoint | create (int value) |
Create new fixed point object from given representation. More... | |
static constexpr FixedPoint | roundRatioDown (unsigned n, unsigned d) |
static constexpr int | shiftHelper (int x, int s) |
Static Public Attributes | |
static constexpr unsigned | FRACTION_BITS = FRACTION_BITS_ |
Number of fractional bits (export template parameter as a constant so that external code can use it more easily). More... | |
Friends | |
constexpr friend FixedPoint | operator+ (FixedPoint x, FixedPoint y) |
constexpr friend FixedPoint | operator- (FixedPoint x, FixedPoint y) |
constexpr friend FixedPoint | operator* (FixedPoint x, FixedPoint y) |
constexpr friend FixedPoint | operator* (FixedPoint x, int y) |
constexpr friend FixedPoint | operator* (int x, FixedPoint y) |
constexpr friend FixedPoint | operator/ (FixedPoint x, FixedPoint y) |
Divides two fixed point numbers. More... | |
constexpr friend FixedPoint | operator/ (FixedPoint x, int y) |
constexpr friend FixedPoint | operator<< (FixedPoint x, int y) |
constexpr friend FixedPoint | operator>> (FixedPoint x, int y) |
constexpr friend bool | operator== (FixedPoint x, FixedPoint y) |
constexpr friend bool | operator!= (FixedPoint x, FixedPoint y) |
constexpr friend bool | operator< (FixedPoint x, FixedPoint y) |
constexpr friend bool | operator<= (FixedPoint x, FixedPoint y) |
constexpr friend bool | operator> (FixedPoint x, FixedPoint y) |
constexpr friend bool | operator>= (FixedPoint x, FixedPoint y) |
A fixed point number, implemented by a 32-bit signed integer.
The FRACTION_BITS template argument selects the position of the "binary point" (base 2 equivalent to decimal point).
Definition at line 15 of file FixedPoint.hh.
|
constexprdefault |
Creates a zero-initialized fixed point object.
Referenced by openmsx::FixedPoint< FRACTION_BITS_ >::create().
|
inlineexplicitconstexpr |
Definition at line 54 of file FixedPoint.hh.
|
inlineexplicitconstexpr |
Definition at line 55 of file FixedPoint.hh.
|
inlineexplicit |
Definition at line 56 of file FixedPoint.hh.
|
inlineexplicit |
Definition at line 57 of file FixedPoint.hh.
|
inlineexplicitconstexpr |
Definition at line 67 of file FixedPoint.hh.
|
inlineconstexpr |
Increase this value with the smallest possible amount.
Typically used to implement counters at the resolution of this datatype.
Definition at line 217 of file FixedPoint.hh.
Referenced by openmsx::YM2413Burczynski::YM2413::generateChannels().
|
inlinestaticconstexpr |
Create new fixed point object from given representation.
Used by the overloaded operators.
value | the internal representation. |
Definition at line 44 of file FixedPoint.hh.
References openmsx::FixedPoint< FRACTION_BITS_ >::FixedPoint().
Referenced by openmsx::FixedPoint< FRACTION_BITS_ >::floor(), openmsx::FixedPoint< FRACTION_BITS_ >::fract(), and openmsx::FixedPoint< FRACTION_BITS_ >::roundRatioDown().
|
inlineconstexpr |
Returns the result of a division between this fixed point number and another, rounded towards zero.
Definition at line 120 of file FixedPoint.hh.
|
inlineconstexpr |
Returns this value rounded down.
The result is equal to FixedPoint(fp.toInt()).
Definition at line 128 of file FixedPoint.hh.
References openmsx::FixedPoint< FRACTION_BITS_ >::create().
|
inlineconstexpr |
Returns the fractional part of this value.
The result is equal to fp - floor(fp).
Definition at line 136 of file FixedPoint.hh.
References openmsx::FixedPoint< FRACTION_BITS_ >::create().
|
inlineconstexpr |
Returns the fractional part of this value as an integer.
The result is equal to (fract() * (1 << FRACTION_BITS)).toInt()
Definition at line 144 of file FixedPoint.hh.
Referenced by openmsx::BlipBuffer::addDelta().
|
inlineconstexpr |
Returns the fractional part of this fixed point number as a double.
The fractional part is never negative, even for negative fixed point numbers. x.toInt() + x.fractionAsDouble() is approximately equal to x.toDouble()
Definition at line 110 of file FixedPoint.hh.
|
inlineconstexpr |
Returns the fractional part of this fixed point number as a float.
The fractional part is never negative, even for negative fixed point numbers. x.toInt() + x.fractionAsFloat() is approximately equal to x.toFloat()
Definition at line 100 of file FixedPoint.hh.
|
inlineconstexpr |
Definition at line 223 of file FixedPoint.hh.
|
inlineconstexpr |
Definition at line 207 of file FixedPoint.hh.
|
inlineconstexpr |
Definition at line 210 of file FixedPoint.hh.
|
inlinestaticconstexpr |
Definition at line 59 of file FixedPoint.hh.
References openmsx::FixedPoint< FRACTION_BITS_ >::create(), and openmsx::FixedPoint< FRACTION_BITS_ >::FRACTION_BITS.
Referenced by openmsx::ResampleLQ< CHANNELS >::ResampleLQ().
|
inline |
Definition at line 228 of file FixedPoint.hh.
|
inlinestaticconstexpr |
Definition at line 63 of file FixedPoint.hh.
References openmsx::x.
|
inlineconstexpr |
Returns the double value that corresponds to this fixed point number.
Definition at line 90 of file FixedPoint.hh.
|
inlineconstexpr |
Returns the float value that corresponds to this fixed point number.
Definition at line 83 of file FixedPoint.hh.
|
inlineconstexpr |
Returns the integer part (rounded down) of this fixed point number.
Note that for negative numbers, rounding occurs away from zero.
Definition at line 76 of file FixedPoint.hh.
References openmsx::FixedPoint< FRACTION_BITS_ >::FRACTION_BITS.
Referenced by openmsx::BlipBuffer::addDelta(), openmsx::YM2413Okazaki::Slot::calc_envelope(), openmsx::YM2413Okazaki::Slot::calc_fixed_env(), openmsx::YM2413Burczynski::Slot::calc_phase(), openmsx::YM2413Burczynski::YM2413::generateChannels(), and openmsx::YM2413Okazaki::Slot::slotOff().
|
friend |
Definition at line 189 of file FixedPoint.hh.
|
friend |
Definition at line 156 of file FixedPoint.hh.
|
friend |
Definition at line 160 of file FixedPoint.hh.
|
friend |
Definition at line 163 of file FixedPoint.hh.
|
friend |
Definition at line 150 of file FixedPoint.hh.
|
friend |
Definition at line 153 of file FixedPoint.hh.
|
friend |
Divides two fixed point numbers.
The fractional part is rounded down.
Definition at line 170 of file FixedPoint.hh.
|
friend |
Definition at line 174 of file FixedPoint.hh.
|
friend |
Definition at line 192 of file FixedPoint.hh.
|
friend |
Definition at line 177 of file FixedPoint.hh.
|
friend |
Definition at line 195 of file FixedPoint.hh.
|
friend |
Definition at line 186 of file FixedPoint.hh.
|
friend |
Definition at line 198 of file FixedPoint.hh.
|
friend |
Definition at line 201 of file FixedPoint.hh.
|
friend |
Definition at line 180 of file FixedPoint.hh.
|
staticconstexpr |
Number of fractional bits (export template parameter as a constant so that external code can use it more easily).
Definition at line 19 of file FixedPoint.hh.
Referenced by openmsx::FixedPoint< FRACTION_BITS_ >::roundRatioDown(), and openmsx::FixedPoint< FRACTION_BITS_ >::toInt().