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) {