From 0eeb7ae3cff9d78e98dc5d9fc09bcb98b10986b9 Mon Sep 17 00:00:00 2001 From: Medusa Slockbower Date: Wed, 2 Jul 2025 17:57:57 -0400 Subject: [PATCH] - More performant roundEven --- include/fennec/math/common.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/include/fennec/math/common.h b/include/fennec/math/common.h index b118537..f2a99d6 100644 --- a/include/fennec/math/common.h +++ b/include/fennec/math/common.h @@ -451,15 +451,23 @@ constexpr vector trunc(const vector& x) template constexpr genType roundEven(genType x) { - const genType e = numeric_limits::epsilon(); - genType f = x - fennec::floor(x); - if (fennec::abs(f - genType(0.5)) > e) + //const genType e = numeric_limits::epsilon(); + //genType f = x - fennec::floor(x); + //if (fennec::abs(f - genType(0.5)) > e) + // return fennec::round(x); + // + //genType i = fennec::floor(x); + //genType r = i / 2; + //bool up = r - fennec::floor(r) > e; + //return i + static_cast(up); + static const genType e = std::numeric_limits::epsilon(); + genType i = fennec::floor(x); + genType f = x - i; + if (abs(f - genType(0.5)) > e) return fennec::round(x); - genType i = fennec::floor(x); - genType r = i / 2; - bool up = r - fennec::floor(r) > e; - return i + static_cast(up); + bool dir = (static_cast(x) % 2); + return dir ? i + 1 : i; } // Vector Specializations ----------------------------------------------------------------------------------------------