Pyrogenesis
trunk
|
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... | |
CFixed & | operator+= (CFixed n) |
Add a CFixed. Might overflow. More... | |
CFixed & | operator-= (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 |
A simple fixed-point number class.
Use 'fixed' rather than using this class directly.
anonymous enum |
|
inlineexplicitprivate |
|
inline |
|
inline |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
|
static |
|
inline |
|
inline |
Returns true if the number is precisely 0.
|
inline |
Compute this*m/d.
Must not have d == 0. Won't overflow if the result can be represented as a CFixed.
|
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.
|
inline |
Multiply by an integer. Avoids overflow by clamping to min/max representable value.
|
inline |
Inequality.
|
inline |
Mod by a fixed. Must not have n == 0. Result has the same sign as n.
|
inline |
Multiply by an integer. Might overflow.
|
private |
|
inline |
Add a CFixed. Might overflow.
|
inline |
Add a CFixed. Might overflow.
|
inline |
Subtract a CFixed. Might overflow.
|
inline |
Negate a CFixed.
|
inline |
Subtract a CFixed. Might overflow.
|
inline |
Divide by a CFixed. Must not have n.IsZero(). Might overflow.
|
inline |
Divide by an integer. Must not have n == 0. Cannot overflow unless n == -1.
|
private |
|
inline |
Numeric comparison.
|
inline |
|
inline |
Numeric comparison.
|
inline |
Equality.
|
inline |
Numeric comparison.
|
inline |
Numeric comparison.
|
inline |
|
static |
|
inline |
|
inline |
|
inline |
Multiply the value by itself.
Might overflow.
|
inline |
Convert to double. Won't be lossy - double can precisely represent all values.
|
inline |
Convert to float. May be lossy - float can't represent all values.
|
inline |
|
inline |
|
inline |
|
inline |
CStr8 CFixed_15_16::ToString | ( | ) | const |
Returns the shortest string such that FromString will parse to the correct value.
|
inlinestatic |
|
private |