Pyrogenesis  trunk
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 > Class Template Reference

A simple fixed-point number class. More...

#include <Fixed.h>

Collaboration diagram for CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >:
Collaboration graph
[legend]

Public Types

enum  { fract_bits = fract_bits_ }
 

Public Member Functions

 CFixed ()
 
T GetInternalValue () const
 
void SetInternalValue (T n)
 
float ToFloat () const
 Convert to float. May be lossy - float can't represent all values. More...
 
double ToDouble () const
 Convert to double. Won't be lossy - double can precisely represent all values. More...
 
int ToInt_RoundToZero () const
 
int ToInt_RoundToInfinity () const
 
int ToInt_RoundToNegInfinity () const
 
int ToInt_RoundToNearest () const
 
CStr8 ToString () const
 Returns the shortest string such that FromString will parse to the correct value. More...
 
bool IsZero () const
 Returns true if the number is precisely 0. More...
 
bool operator== (CFixed n) const
 Equality. More...
 
bool operator!= (CFixed n) const
 Inequality. More...
 
bool operator<= (CFixed n) const
 Numeric comparison. More...
 
bool operator< (CFixed n) const
 Numeric comparison. More...
 
bool operator>= (CFixed n) const
 Numeric comparison. More...
 
bool operator> (CFixed n) const
 Numeric comparison. More...
 
CFixed operator+ (CFixed n) const
 Add a CFixed. Might overflow. More...
 
CFixed operator- (CFixed n) const
 Subtract a CFixed. Might overflow. More...
 
CFixedoperator+= (CFixed n)
 Add a CFixed. Might overflow. More...
 
CFixedoperator-= (CFixed n)
 Subtract a CFixed. Might overflow. More...
 
CFixed operator- () const
 Negate a CFixed. More...
 
CFixed operator>> (int n) const
 
CFixed operator<< (int n) const
 
CFixed operator/ (CFixed n) const
 Divide by a CFixed. Must not have n.IsZero(). Might overflow. More...
 
CFixed operator* (int n) const
 Multiply by an integer. Might overflow. More...
 
CFixed MultiplyClamp (int n) const
 Multiply by an integer. Avoids overflow by clamping to min/max representable value. More...
 
CFixed operator/ (int n) const
 Divide by an integer. Must not have n == 0. Cannot overflow unless n == -1. More...
 
CFixed operator% (CFixed n) const
 Mod by a fixed. Must not have n == 0. Result has the same sign as n. More...
 
CFixed Absolute () const
 
CFixed Multiply (CFixed n) const
 Multiply by a CFixed. More...
 
CFixed Square () const
 Multiply the value by itself. More...
 
CFixed MulDiv (CFixed m, CFixed d) const
 Compute this*m/d. More...
 
CFixed Sqrt () const
 

Static Public Member Functions

static CFixed Zero ()
 
static CFixed Epsilon ()
 
static CFixed Pi ()
 
static CFixed FromInt (int n)
 
static CFixed FromFloat (float n)
 
static CFixed FromDouble (double n)
 
static CFixed FromString (const CStr8 &s)
 
static CFixed FromString (const CStrW &s)
 

Private Member Functions

 CFixed (T v)
 
CFixed operator* (float n) const
 
CFixed operator/ (float n) const
 

Private Attributes

T value
 

Detailed Description

template<typename T, T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
class CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >

A simple fixed-point number class.

Use 'fixed' rather than using this class directly.

Member Enumeration Documentation

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
anonymous enum
Enumerator
fract_bits 

Constructor & Destructor Documentation

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::CFixed ( T  v)
inlineexplicitprivate
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::CFixed ( )
inline

Member Function Documentation

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::Absolute ( ) const
inline
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
static CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::Epsilon ( )
inlinestatic
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
static CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::FromDouble ( double  n)
inlinestatic
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
static CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::FromFloat ( float  n)
inlinestatic
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
static CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::FromInt ( int  n)
inlinestatic
CFixed_15_16 CFixed_15_16::FromString ( const CStr8 &  s)
static
CFixed_15_16 CFixed_15_16::FromString ( const CStrW &  s)
static
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
T CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::GetInternalValue ( ) const
inline
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
bool CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::IsZero ( ) const
inline

Returns true if the number is precisely 0.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::MulDiv ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  m,
CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  d 
) const
inline

Compute this*m/d.

Must not have d == 0. Won't overflow if the result can be represented as a CFixed.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::Multiply ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Multiply by a CFixed.

Likely to overflow if both numbers are large, so we use an ugly name instead of operator* to make it obvious.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::MultiplyClamp ( int  n) const
inline

Multiply by an integer. Avoids overflow by clamping to min/max representable value.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
bool CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator!= ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Inequality.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator% ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Mod by a fixed. Must not have n == 0. Result has the same sign as n.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator* ( int  n) const
inline

Multiply by an integer. Might overflow.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator* ( float  n) const
private
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator+ ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Add a CFixed. Might overflow.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed& CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator+= ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n)
inline

Add a CFixed. Might overflow.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator- ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Subtract a CFixed. Might overflow.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator- ( ) const
inline

Negate a CFixed.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed& CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator-= ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n)
inline

Subtract a CFixed. Might overflow.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator/ ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Divide by a CFixed. Must not have n.IsZero(). Might overflow.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator/ ( int  n) const
inline

Divide by an integer. Must not have n == 0. Cannot overflow unless n == -1.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator/ ( float  n) const
private
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
bool CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator< ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Numeric comparison.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator<< ( int  n) const
inline
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
bool CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator<= ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Numeric comparison.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
bool CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator== ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Equality.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
bool CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator> ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Numeric comparison.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
bool CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator>= ( CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >  n) const
inline

Numeric comparison.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::operator>> ( int  n) const
inline
CFixed_15_16 CFixed_15_16::Pi ( )
static
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
void CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::SetInternalValue ( T  n)
inline
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::Sqrt ( ) const
inline
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::Square ( ) const
inline

Multiply the value by itself.

Might overflow.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
double CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToDouble ( ) const
inline

Convert to double. Won't be lossy - double can precisely represent all values.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
float CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToFloat ( ) const
inline

Convert to float. May be lossy - float can't represent all values.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
int CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToInt_RoundToInfinity ( ) const
inline
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
int CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToInt_RoundToNearest ( ) const
inline
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
int CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToInt_RoundToNegInfinity ( ) const
inline
template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
int CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToInt_RoundToZero ( ) const
inline
CStr8 CFixed_15_16::ToString ( ) const

Returns the shortest string such that FromString will parse to the correct value.

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
static CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::Zero ( )
inlinestatic

Member Data Documentation

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
T CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::value
private

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