mirror of
https://github.com/g-truc/glm.git
synced 2024-11-23 01:14:34 +00:00
Merge pull request #271 from plasmacel/master
fast branchless sign function #271
This commit is contained in:
commit
fe20b216a0
@ -151,7 +151,7 @@ namespace detail
|
||||
}
|
||||
|
||||
// sign
|
||||
//Try something like based on x >> 31 to get the sign bit
|
||||
// fast and works for any type
|
||||
template <typename genFIType>
|
||||
GLM_FUNC_QUALIFIER genFIType sign(genFIType x)
|
||||
{
|
||||
@ -159,14 +159,7 @@ namespace detail
|
||||
std::numeric_limits<genFIType>::is_iec559 ||
|
||||
(std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer), "'sign' only accept signed inputs");
|
||||
|
||||
genFIType result;
|
||||
if(x > genFIType(0))
|
||||
result = genFIType(1);
|
||||
else if(x < genFIType(0))
|
||||
result = genFIType(-1);
|
||||
else
|
||||
result = genFIType(0);
|
||||
return result;
|
||||
return genFIType(genFIType(0) < x) - (x < genFIType(0));
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
|
Loading…
Reference in New Issue
Block a user