- More performant roundEven

This commit is contained in:
2025-07-02 17:57:57 -04:00
parent e2ea22f12d
commit 0eeb7ae3cf

View File

@@ -451,15 +451,23 @@ constexpr vector<genType, i...> trunc(const vector<genType, i...>& x)
template<typename genType> template<typename genType>
constexpr genType roundEven(genType x) constexpr genType roundEven(genType x)
{ {
const genType e = numeric_limits<genType>::epsilon(); //const genType e = numeric_limits<genType>::epsilon();
genType f = x - fennec::floor(x); //genType f = x - fennec::floor(x);
if (fennec::abs(f - genType(0.5)) > e) //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<genType>(up);
static const genType e = std::numeric_limits<genType>::epsilon();
genType i = fennec::floor(x);
genType f = x - i;
if (abs(f - genType(0.5)) > e)
return fennec::round(x); return fennec::round(x);
genType i = fennec::floor(x); bool dir = (static_cast<int>(x) % 2);
genType r = i / 2; return dir ? i + 1 : i;
bool up = r - fennec::floor(r) > e;
return i + static_cast<genType>(up);
} }
// Vector Specializations ---------------------------------------------------------------------------------------------- // Vector Specializations ----------------------------------------------------------------------------------------------