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