Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
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...
 
constexpr int ToInt_RoundToZero () const
 
constexpr int ToInt_RoundToInfinity () const
 
constexpr int ToInt_RoundToNegInfinity () const
 
constexpr int ToInt_RoundToNearest () const
 
CStr8 ToString () const
 Returns the shortest string such that FromString will parse to the correct value. More...
 
constexpr bool IsZero () const
 Returns true if the number is precisely 0. More...
 
constexpr bool operator== (CFixed n) const
 Equality. More...
 
constexpr bool operator!= (CFixed n) const
 Inequality. More...
 
constexpr bool operator<= (CFixed n) const
 Numeric comparison. More...
 
constexpr bool operator< (CFixed n) const
 Numeric comparison. More...
 
constexpr bool operator>= (CFixed n) const
 Numeric comparison. More...
 
constexpr 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...
 
constexpr CFixedoperator+= (CFixed n)
 Add a CFixed. Might overflow. More...
 
constexpr 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...
 
constexpr 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...
 
constexpr CFixed operator% (CFixed n) const
 Mod by a fixed. Must not have n == 0. Result has the same sign as n. More...
 
constexpr CFixed Absolute () const
 
CFixed Multiply (CFixed n) const
 Multiply by a CFixed. More...
 
constexpr CFixed Square () const
 Multiply the value by itself. More...
 
CFixed MulDiv (CFixed m, CFixed d) const
 Compute this*m/d. More...
 
constexpr CFixed Sqrt () const
 

Static Public Member Functions

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

Private Member Functions

constexpr 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

◆ anonymous enum

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

◆ CFixed() [1/2]

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

◆ CFixed() [2/2]

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

◆ Absolute()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::Absolute ( ) const
inlineconstexpr

◆ Epsilon()

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

◆ FromDouble()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
static constexpr CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::FromDouble ( double  n)
inlinestaticconstexpr

◆ FromFloat()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
static constexpr CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::FromFloat ( float  n)
inlinestaticconstexpr

◆ FromFraction()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
static constexpr CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::FromFraction ( int  n,
int  d 
)
inlinestaticconstexpr

◆ FromInt()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
static constexpr CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::FromInt ( int  n)
inlinestaticconstexpr

◆ FromString() [1/2]

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

◆ FromString() [2/2]

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

◆ GetInternalValue()

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

◆ IsZero()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr bool CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::IsZero ( ) const
inlineconstexpr

Returns true if the number is precisely 0.

◆ MulDiv()

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.

◆ Multiply()

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.

◆ MultiplyClamp()

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

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

◆ operator!=()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr 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
inlineconstexpr

Inequality.

◆ operator%()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr 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
inlineconstexpr

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

◆ operator*() [1/2]

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

◆ operator*() [2/2]

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.

◆ operator+()

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.

◆ operator+=()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr 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)
inlineconstexpr

Add a CFixed. Might overflow.

◆ operator-() [1/2]

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.

◆ operator-() [2/2]

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.

◆ operator-=()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr 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)
inlineconstexpr

Subtract a CFixed. Might overflow.

◆ operator/() [1/3]

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.

◆ operator/() [2/3]

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

◆ operator/() [3/3]

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.

◆ operator<()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr 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
inlineconstexpr

Numeric comparison.

◆ operator<<()

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

◆ operator<=()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr 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
inlineconstexpr

Numeric comparison.

◆ operator==()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr 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
inlineconstexpr

Equality.

◆ operator>()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr 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
inlineconstexpr

Numeric comparison.

◆ operator>=()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr 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
inlineconstexpr

Numeric comparison.

◆ operator>>()

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

◆ Pi()

CFixed_15_16 CFixed_15_16::Pi
static

◆ SetInternalValue()

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

◆ Sqrt()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::Sqrt ( ) const
inlineconstexpr

◆ Square()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr CFixed CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::Square ( ) const
inlineconstexpr

Multiply the value by itself.

Might overflow.

◆ ToDouble()

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.

◆ ToFloat()

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.

◆ ToInt_RoundToInfinity()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr int CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToInt_RoundToInfinity ( ) const
inlineconstexpr

◆ ToInt_RoundToNearest()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr int CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToInt_RoundToNearest ( ) const
inlineconstexpr

◆ ToInt_RoundToNegInfinity()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr int CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToInt_RoundToNegInfinity ( ) const
inlineconstexpr

◆ ToInt_RoundToZero()

template<typename T , T max_t, int total_bits, int int_bits, int fract_bits_, int fract_pow2>
constexpr int CFixed< T, max_t, total_bits, int_bits, fract_bits_, fract_pow2 >::ToInt_RoundToZero ( ) const
inlineconstexpr

◆ ToString()

CStr8 CFixed_15_16::ToString

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

◆ Zero()

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

◆ value

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: