From 0f89a4e3db83e58c8e6e36d84fe76ab5981429ad Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 7 Sep 2024 14:59:16 +0200 Subject: [PATCH] Tier0: only ABS on signed types in ExtremeElementABS Bug fix. --- src/public/tier0/utility.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/public/tier0/utility.h b/src/public/tier0/utility.h index 3e4c47fa..107daba8 100644 --- a/src/public/tier0/utility.h +++ b/src/public/tier0/utility.h @@ -94,9 +94,17 @@ string Format(const char* szFormat, ...); template Iter ExtremeElementABS(Iter first, Iter last, Compare compare) { - auto abs_compare = [compare](LONG a, LONG b) + using ValueType = typename std::iterator_traits::value_type; + auto abs_compare = [compare](ValueType a, ValueType b) { - return compare(abs(a), abs(b)); + if constexpr (std::is_signed_v) + { + return compare(abs(a), abs(b)); + } + else + { + return compare(a, b); + } }; return std::min_element(first, last, abs_compare);