FFixed
Q16.16 fixed point for gameplay state that must come out the same bits on every machine and every build: the float rules a compiler may follow (contraction into FMA, x87 vs SSE, reassociation under fast-math) differ across toolchains, and integer arithmetic does not. Products and quotients widen to 64 bits before they narrow, and both round toward negative infinity, so the result never depends on the sign convention of a division.
- Module
- Game
- Header
#include "Rollback/DeterministicMath.h"- Namespace
Mowo
Inside one binary, strict IEEE float (the engine builds /fp:precise) is already deterministic; FFixed is for state that crosses builds — a replay, a dedicated server on another platform.
Properties
| Type | Name | Description |
|---|---|---|
static constexpr int32_t | kFractionBits | Default 16. |
static constexpr int32_t | kOne | Default 1 << kFractionBits. |
int32_t | raw | Default 0. |
bool operator<(FFixed other) | const |
Public functions
| Returns | Name | Description |
|---|---|---|
FFixed | FromRaw | |
FFixed | FromInt | |
FFixed | FromFloat | Rounded to the nearest representable value; only for authored constants and inputs entering the simulation, never inside it. |
float | ToFloat | |
int32_t | ToIntFloor | |
FFixed | operator+ | |
FFixed | operator- | |
FFixed | operator- | |
FFixed | operator* | |
FFixed | operator/ | |
FFixed& | operator+= | |
FFixed& | operator-= | |
bool | operator== | |
bool | operator!= | |
bool | operator> | |
bool | operator>= | |
FFixed | Abs | |
FFixed | Clamp | |
FFixed | Sqrt | Integer square root (Newton on the widened value): exact to the last fractional bit and the same on every machine. |
Function details
FromRaw
static constexpr FFixed FromRaw(int32_t value)FromInt
static constexpr FFixed FromInt(int32_t value)FromFloat
static FFixed FromFloat(float value)Rounded to the nearest representable value; only for authored constants and inputs entering the simulation, never inside it.
ToFloat
float ToFloat() constToIntFloor
int32_t ToIntFloor() constoperator+
FFixed operator+(FFixed other) constoperator-
FFixed operator-(FFixed other) constoperator-
FFixed operator-() constoperator*
FFixed operator*(FFixed other) constoperator/
FFixed operator/(FFixed other) constoperator+=
FFixed& operator+=(FFixed other)operator-=
FFixed& operator-=(FFixed other)operator==
bool operator==(FFixed other) constoperator!=
bool operator!=(FFixed other) constoperator>
bool operator>(FFixed other) constoperator>=
bool operator>=(FFixed other) constAbs
static FFixed Abs(FFixed value)Clamp
static FFixed Clamp(FFixed value, FFixed lo, FFixed hi)Sqrt
static FFixed Sqrt(FFixed value)Integer square root (Newton on the widened value): exact to the last fractional bit and the same on every machine.