Skip to content

Fixed Point Arithmetic

include/math/fixed.h View source View on GitHub
fx32_32_t fx_parse(const char *str, char **endptr);
fx32_32_t fx_add(fx32_32_t a, fx32_32_t b);
fx32_32_t fx_sub(fx32_32_t a, fx32_32_t b);
fx32_32_t fx_mul(fx32_32_t a, fx32_32_t b);
fx32_32_t fx_div(fx32_32_t a, fx32_32_t b);
fx32_32_t fx_from_int(int64_t x);
int64_t fx_to_int(fx32_32_t x);
fx32_32_t fx_from_float(double v);
fx32_32_t fx_min(fx32_32_t a, fx32_32_t b);
fx32_32_t fx_max(fx32_32_t a, fx32_32_t b);
fx32_32_t fx_clamp(fx32_32_t x, fx32_32_t lo, fx32_32_t hi);
fx32_32_t fx_pow_i32(fx32_32_t base, int exp);
fx32_32_t fx_sqrt(fx32_32_t x);
fx32_32_t fx_ceil(fx32_32_t x);
fx32_32_t fx_floor(fx32_32_t x);
#define FX_ONE ((fx32_32_t) (1LL << 32))
#define FX_HALF ((fx32_32_t) (1LL << 31))
#define FX(x) ((fx32_32_t) ((x) * 4294967296.0 + 0.5))
#define FX_FROM_RATIO(n, d) ((fx32_32_t) (((__int128) (n) << 32) / (d)))