- More performant roundEven
This commit is contained in:
@@ -451,15 +451,23 @@ constexpr vector<genType, i...> trunc(const vector<genType, i...>& x)
|
||||
template<typename genType>
|
||||
constexpr genType roundEven(genType x)
|
||||
{
|
||||
const genType e = numeric_limits<genType>::epsilon();
|
||||
genType f = x - fennec::floor(x);
|
||||
if (fennec::abs(f - genType(0.5)) > e)
|
||||
//const genType e = numeric_limits<genType>::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<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);
|
||||
|
||||
genType i = fennec::floor(x);
|
||||
genType r = i / 2;
|
||||
bool up = r - fennec::floor(r) > e;
|
||||
return i + static_cast<genType>(up);
|
||||
bool dir = (static_cast<int>(x) % 2);
|
||||
return dir ? i + 1 : i;
|
||||
}
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user