openMSX
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
openmsx::FixedPoint< FRACTION_BITS_ > Class Template Reference

A fixed point number, implemented by a 32-bit signed integer. More...

#include <FixedPoint.hh>

Inheritance diagram for openmsx::FixedPoint< FRACTION_BITS_ >:
Inheritance graph
[legend]

Public Member Functions

 FixedPoint ()
 Creates an uninitialized fixed point object. More...
 
 FixedPoint (const int i)
 
 FixedPoint (const unsigned i)
 
 FixedPoint (const float f)
 
 FixedPoint (const double d)
 
template<unsigned BITS2>
 FixedPoint (FixedPoint< BITS2 > other)
 
int toInt () const
 Returns the integer part (rounded down) of this fixed point number. More...
 
float toFloat () const
 Returns the float value that corresponds to this fixed point number. More...
 
double toDouble () const
 Returns the double value that corresponds to this fixed point number. More...
 
float fractionAsFloat () const
 Returns the fractional part of this fixed point number as a float. More...
 
double fractionAsDouble () const
 Returns the fractional part of this fixed point number as a double. More...
 
int divAsInt (const FixedPoint other) const
 Returns the result of a division between this fixed point number and another, rounded towards zero. More...
 
FixedPoint floor () const
 Returns this value rounded down. More...
 
FixedPoint fract () const
 Returns the fractional part of this value. More...
 
unsigned fractAsInt () const
 Returns the fractional part of this value as an integer. More...
 
FixedPoint operator+ (const FixedPoint other) const
 
FixedPoint operator- (const FixedPoint other) const
 
FixedPoint operator* (const FixedPoint other) const
 
FixedPoint operator* (const int i) const
 
FixedPoint operator/ (const FixedPoint other) const
 Divides two fixed point numbers. More...
 
FixedPoint operator/ (const int i) const
 
FixedPoint operator<< (const int b) const
 
FixedPoint operator>> (const int b) const
 
bool operator== (const FixedPoint other) const
 
bool operator!= (const FixedPoint other) const
 
bool operator< (const FixedPoint other) const
 
bool operator<= (const FixedPoint other) const
 
bool operator> (const FixedPoint other) const
 
bool operator>= (const FixedPoint other) const
 
void operator+= (const FixedPoint other)
 
void operator-= (const FixedPoint other)
 
void addQuantum ()
 Increase this value with the smallest possible amount. More...
 
int getRawValue () const
 
template<typename Archive >
void serialize (Archive &ar, unsigned)
 

Static Public Member Functions

static FixedPoint create (const int value)
 Create new fixed point object from given representation. More...
 
static FixedPoint roundRatioDown (unsigned n, unsigned d)
 
static int shiftHelper (int x, int s)
 

Static Public Attributes

static const 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...
 

Detailed Description

template<unsigned FRACTION_BITS_>
class openmsx::FixedPoint< FRACTION_BITS_ >

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 14 of file FixedPoint.hh.

Constructor & Destructor Documentation

template<unsigned FRACTION_BITS_>
openmsx::FixedPoint< FRACTION_BITS_ >::FixedPoint ( )
inlineexplicit

Creates an uninitialized fixed point object.

This must be public to allow arrays of FixedPoint objects.

Definition at line 52 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
openmsx::FixedPoint< FRACTION_BITS_ >::FixedPoint ( const int  i)
inlineexplicit

Definition at line 56 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
openmsx::FixedPoint< FRACTION_BITS_ >::FixedPoint ( const unsigned  i)
inlineexplicit

Definition at line 57 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
openmsx::FixedPoint< FRACTION_BITS_ >::FixedPoint ( const float  f)
inlineexplicit

Definition at line 58 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
openmsx::FixedPoint< FRACTION_BITS_ >::FixedPoint ( const double  d)
inlineexplicit

Definition at line 59 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
template<unsigned BITS2>
openmsx::FixedPoint< FRACTION_BITS_ >::FixedPoint ( FixedPoint< BITS2 >  other)
inlineexplicit

Definition at line 69 of file FixedPoint.hh.

Member Function Documentation

template<unsigned FRACTION_BITS_>
void openmsx::FixedPoint< FRACTION_BITS_ >::addQuantum ( )
inline

Increase this value with the smallest possible amount.

Typically used to implement counters at the resolution of this datatype.

Definition at line 216 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
static FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::create ( const int  value)
inlinestatic
template<unsigned FRACTION_BITS_>
int openmsx::FixedPoint< FRACTION_BITS_ >::divAsInt ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Returns the result of a division between this fixed point number and another, rounded towards zero.

Definition at line 122 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::floor ( ) const
inline

Returns this value rounded down.

The result is equal to FixedPoint(fp.toInt()).

Definition at line 130 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::fract ( ) const
inline

Returns the fractional part of this value.

The result is equal to fp - floor(fp).

Definition at line 138 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
unsigned openmsx::FixedPoint< FRACTION_BITS_ >::fractAsInt ( ) const
inline

Returns the fractional part of this value as an integer.

The result is equal to (fract() * (1 << FRACTION_BITS)).toInt()

Definition at line 146 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
double openmsx::FixedPoint< FRACTION_BITS_ >::fractionAsDouble ( ) const
inline

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 112 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
float openmsx::FixedPoint< FRACTION_BITS_ >::fractionAsFloat ( ) const
inline

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 102 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
int openmsx::FixedPoint< FRACTION_BITS_ >::getRawValue ( ) const
inline

Definition at line 222 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
bool openmsx::FixedPoint< FRACTION_BITS_ >::operator!= ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Definition at line 188 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::operator* ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Definition at line 158 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::operator* ( const int  i) const
inline

Definition at line 162 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::operator+ ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Definition at line 152 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
void openmsx::FixedPoint< FRACTION_BITS_ >::operator+= ( const FixedPoint< FRACTION_BITS_ >  other)
inline

Definition at line 206 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::operator- ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Definition at line 155 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
void openmsx::FixedPoint< FRACTION_BITS_ >::operator-= ( const FixedPoint< FRACTION_BITS_ >  other)
inline

Definition at line 209 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::operator/ ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Divides two fixed point numbers.

The fractional part is rounded down.

Definition at line 169 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::operator/ ( const int  i) const
inline

Definition at line 173 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
bool openmsx::FixedPoint< FRACTION_BITS_ >::operator< ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Definition at line 191 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::operator<< ( const int  b) const
inline

Definition at line 176 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
bool openmsx::FixedPoint< FRACTION_BITS_ >::operator<= ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Definition at line 194 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
bool openmsx::FixedPoint< FRACTION_BITS_ >::operator== ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Definition at line 185 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
bool openmsx::FixedPoint< FRACTION_BITS_ >::operator> ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Definition at line 197 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
bool openmsx::FixedPoint< FRACTION_BITS_ >::operator>= ( const FixedPoint< FRACTION_BITS_ >  other) const
inline

Definition at line 200 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::operator>> ( const int  b) const
inline

Definition at line 179 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
static FixedPoint openmsx::FixedPoint< FRACTION_BITS_ >::roundRatioDown ( unsigned  n,
unsigned  d 
)
inlinestatic

Definition at line 61 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
template<typename Archive >
void openmsx::FixedPoint< FRACTION_BITS_ >::serialize ( Archive &  ar,
unsigned   
)
inline

Definition at line 227 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
static int openmsx::FixedPoint< FRACTION_BITS_ >::shiftHelper ( int  x,
int  s 
)
inlinestatic

Definition at line 65 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
double openmsx::FixedPoint< FRACTION_BITS_ >::toDouble ( ) const
inline

Returns the double value that corresponds to this fixed point number.

Definition at line 92 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
float openmsx::FixedPoint< FRACTION_BITS_ >::toFloat ( ) const
inline

Returns the float value that corresponds to this fixed point number.

Definition at line 85 of file FixedPoint.hh.

template<unsigned FRACTION_BITS_>
int openmsx::FixedPoint< FRACTION_BITS_ >::toInt ( ) const
inline

Returns the integer part (rounded down) of this fixed point number.

Note that for negative numbers, rounding occurs away from zero.

Definition at line 78 of file FixedPoint.hh.

Referenced by openmsx::YM2413Burczynski::Slot::calc_phase(), openmsx::YMF262Channel::chan_calc(), openmsx::YMF262Channel::chan_calc_ext(), openmsx::Y8950Slot::slotOff(), and openmsx::Y8950Slot::slotOn().

Member Data Documentation

template<unsigned FRACTION_BITS_>
const unsigned openmsx::FixedPoint< FRACTION_BITS_ >::FRACTION_BITS = FRACTION_BITS_
static

Number of fractional bits (export template parameter as a constant so that external code can use it more easily).

Definition at line 18 of file FixedPoint.hh.

Referenced by openmsx::FixedPoint< EG_DP_BITS-EG_BITS >::toInt().


The documentation for this class was generated from the following file: