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. | |
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. | |
constexpr float | toFloat () const |
Returns the float value that corresponds to this fixed point number. | |
constexpr double | toDouble () const |
Returns the double value that corresponds to this fixed point number. | |
constexpr float | fractionAsFloat () const |
Returns the fractional part of this fixed point number as a float. | |
constexpr double | fractionAsDouble () const |
Returns the fractional part of this fixed point number as a double. | |
constexpr int | divAsInt (FixedPoint other) const |
Returns the result of a division between this fixed point number and another, rounded towards zero. | |
constexpr FixedPoint | floor () const |
Returns this value rounded down. | |
constexpr FixedPoint | fract () const |
Returns the fractional part of this value. | |
constexpr unsigned | fractAsInt () const |
Returns the fractional part of this value as an integer. | |
constexpr auto | operator<=> (const FixedPoint &) const =default |
constexpr void | operator+= (FixedPoint other) |
constexpr void | operator-= (FixedPoint other) |
constexpr void | addQuantum () |
Increase this value with the smallest possible amount. | |
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. | |
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). | |
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. | |
constexpr friend FixedPoint | operator/ (FixedPoint x, int y) |
constexpr friend FixedPoint | operator<< (FixedPoint x, int y) |
constexpr friend FixedPoint | operator>> (FixedPoint x, int 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 16 of file FixedPoint.hh.
|
constexprdefault |
Creates a zero-initialized fixed point object.
Referenced by openmsx::FixedPoint< FRACTION_BITS_ >::create().
|
inlineexplicitconstexpr |
Definition at line 55 of file FixedPoint.hh.
|
inlineexplicitconstexpr |
Definition at line 56 of file FixedPoint.hh.
|
inlineexplicit |
Definition at line 57 of file FixedPoint.hh.
|
inlineexplicit |
Definition at line 58 of file FixedPoint.hh.
|
inlineexplicitconstexpr |
Definition at line 68 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 200 of file FixedPoint.hh.
Referenced by openmsx::YM2413Burczynski::YM2413::generateChannels(), and TEST_CASE().
|
inlinestaticconstexpr |
Create new fixed point object from given representation.
Used by the overloaded operators.
value | the internal representation. |
Definition at line 45 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 121 of file FixedPoint.hh.
Referenced by TEST_CASE().
|
inlineconstexpr |
Returns this value rounded down.
The result is equal to FixedPoint(fp.toInt()).
Definition at line 129 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 137 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 145 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 111 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 101 of file FixedPoint.hh.
|
inlineconstexpr |
Definition at line 206 of file FixedPoint.hh.
|
inlineconstexpr |
Definition at line 190 of file FixedPoint.hh.
|
inlineconstexpr |
Definition at line 193 of file FixedPoint.hh.
|
constexprdefault |
|
inlinestaticconstexpr |
Definition at line 60 of file FixedPoint.hh.
References openmsx::FixedPoint< FRACTION_BITS_ >::create(), and openmsx::FixedPoint< FRACTION_BITS_ >::FRACTION_BITS.
|
inline |
Definition at line 211 of file FixedPoint.hh.
|
inlinestaticconstexpr |
Definition at line 64 of file FixedPoint.hh.
|
inlineconstexpr |
Returns the double value that corresponds to this fixed point number.
Definition at line 91 of file FixedPoint.hh.
|
inlineconstexpr |
Returns the float value that corresponds to this fixed point number.
Definition at line 84 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 77 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 157 of file FixedPoint.hh.
|
friend |
Definition at line 161 of file FixedPoint.hh.
|
friend |
Definition at line 164 of file FixedPoint.hh.
|
friend |
Definition at line 151 of file FixedPoint.hh.
|
friend |
Definition at line 154 of file FixedPoint.hh.
|
friend |
Divides two fixed point numbers.
The fractional part is rounded down.
Definition at line 171 of file FixedPoint.hh.
|
friend |
Definition at line 175 of file FixedPoint.hh.
|
friend |
Definition at line 178 of file FixedPoint.hh.
|
friend |
Definition at line 181 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 20 of file FixedPoint.hh.
Referenced by openmsx::FixedPoint< FRACTION_BITS_ >::roundRatioDown(), and openmsx::FixedPoint< FRACTION_BITS_ >::toInt().