From abec5474f0003a30846164bab3754f7538242e76 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 14 Aug 2026 16:34:58 +0300 Subject: [PATCH] Add trunc() and fract() for util::fixed_point --- libs/util/include/psemek/util/fixed_point.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libs/util/include/psemek/util/fixed_point.hpp b/libs/util/include/psemek/util/fixed_point.hpp index 472ec7d7..b632135f 100644 --- a/libs/util/include/psemek/util/fixed_point.hpp +++ b/libs/util/include/psemek/util/fixed_point.hpp @@ -363,6 +363,25 @@ namespace psemek::util return FP::from_rep(((x.rep() - static_cast(1)) & ~fractional_mask) + fixed_point_one); } + template + constexpr fixed_point trunc(fixed_point x) + { + if (S && x < fixed_point{0}) + { + return ceil(x); + } + else + { + return floor(x); + } + } + + template + constexpr fixed_point fract(fixed_point x) + { + return x - trunc(x); + } + template constexpr fixed_point round(fixed_point x) {