diff options
| author | batsumaru <> | 2026-08-09 10:54:32 +0900 |
|---|---|---|
| committer | batsumaru <> | 2026-08-09 10:54:32 +0900 |
| commit | 86e6b2a2a35f46550439262978d52bdeb93c6dc6 (patch) | |
| tree | 06324833942126ca5132ec595d8880c8a8a55eed /include/fixed_point.h | |
Initial commit, fixed point addition
Diffstat (limited to 'include/fixed_point.h')
| -rw-r--r-- | include/fixed_point.h | 20 |
1 files changed, 20 insertions, 0 deletions
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 <cstdint> +#include <type_traits> + +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>, "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 |
