Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>

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/ (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 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.

Definition at line 115 of file Fixed.h.

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 

Definition at line 123 of file Fixed.h.

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

Definition at line 120 of file Fixed.h.

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

Definition at line 125 of file Fixed.h.

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

Definition at line 284 of file Fixed.h.

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

Definition at line 128 of file Fixed.h.

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

Definition at line 149 of file Fixed.h.

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

Definition at line 141 of file Fixed.h.

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

Definition at line 136 of file Fixed.h.

CFixed_15_16 CFixed_15_16::FromString ( const CStr8 &  s)
static

Definition at line 27 of file Fixed.cpp.

CFixed_15_16 CFixed_15_16::FromString ( const CStrW &  s)
static

Definition at line 90 of file Fixed.cpp.

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

Definition at line 131 of file Fixed.h.

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.

Definition at line 199 of file Fixed.h.

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.

Definition at line 310 of file Fixed.h.

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.

Definition at line 290 of file Fixed.h.

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.

Definition at line 205 of file Fixed.h.

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.

Definition at line 273 of file Fixed.h.

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.

Definition at line 259 of file Fixed.h.

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.

Definition at line 222 of file Fixed.h.

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.

Definition at line 236 of file Fixed.h.

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.

Definition at line 229 of file Fixed.h.

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.

Definition at line 242 of file Fixed.h.

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.

Definition at line 239 of file Fixed.h.

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.

Definition at line 249 of file Fixed.h.

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.

Definition at line 266 of file Fixed.h.

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.

Definition at line 211 of file Fixed.h.

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.

Definition at line 208 of file Fixed.h.

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.

Definition at line 202 of file Fixed.h.

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.

Definition at line 217 of file Fixed.h.

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.

Definition at line 214 of file Fixed.h.

CFixed_15_16 CFixed_15_16::Pi ( )
static

Definition at line 182 of file Fixed.cpp.

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

Definition at line 132 of file Fixed.h.

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

Definition at line 317 of file Fixed.h.

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.

Definition at line 302 of file Fixed.h.

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.

Definition at line 167 of file Fixed.h.

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.

Definition at line 161 of file Fixed.h.

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

Definition at line 180 of file Fixed.h.

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

Definition at line 190 of file Fixed.h.

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

Definition at line 185 of file Fixed.h.

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

Definition at line 172 of file Fixed.h.

CStr8 CFixed_15_16::ToString ( ) const

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

Definition at line 96 of file Fixed.cpp.

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

Definition at line 127 of file Fixed.h.

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

Definition at line 118 of file Fixed.h.


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