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