From 86e6b2a2a35f46550439262978d52bdeb93c6dc6 Mon Sep 17 00:00:00 2001 From: batsumaru <> Date: Sun, 9 Aug 2026 10:54:32 +0900 Subject: Initial commit, fixed point addition --- include/fixed_point.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 include/fixed_point.h (limited to 'include') diff --git a/include/fixed_point.h b/include/fixed_point.h new file mode 100644 index 0000000..254bc91 --- /dev/null +++ b/include/fixed_point.h @@ -0,0 +1,20 @@ +#ifndef FIXED_POINT_H +#define FIXED_POINT_H + +#include +#include + +struct fp_t { + std::int32_t raw; + + static constexpr fp_t from_raw(std::int32_t r) { return fp_t{r}; } + static constexpr fp_t from_int(std::int32_t i) { return fp_t{i << 16}; } + + fp_t operator+(const fp_t& other) const; + bool operator==(const fp_t& other) const; +}; + +static_assert(std::is_trivially_copyable_v, "fp_t must remain trivially copyable for rollback determinism"); +static_assert(sizeof(fp_t) == 4, "fp_t must stay 4 bytes — check for unexpected padding"); + +#endif // !FIXED_POINT_H -- cgit v1.3