Fix abs(fixed_point), lmao

This commit is contained in:
Nikita Lisitsa 2025-10-19 02:40:35 +03:00
parent 615ee51229
commit 64ffe27c2a

View file

@ -337,9 +337,8 @@ namespace psemek::util
constexpr fixed_point<I, F, S> abs(fixed_point<I, F, S> x) constexpr fixed_point<I, F, S> abs(fixed_point<I, F, S> x)
{ {
using FP = fixed_point<I, F, S>; using FP = fixed_point<I, F, S>;
using rep_type = typename FP::rep_type;
if constexpr (S) if constexpr (S)
return FP::from_rep(x.rep() & ~(static_cast<rep_type>(1) << (I + F - 1))); return FP::from_rep(std::abs(x.rep()));
else else
return x; return x;
} }