maths: use __builtin_signbit to handle +- zeros
This commit is contained in:
parent
cf9db48e0e
commit
93ed983a6f
@ -104,9 +104,9 @@ digits [[gnu::pure]] (const T& value);
|
|||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
constexpr int sign (int);
|
||||||
typename try_signed<T>::type
|
constexpr float sign (float);
|
||||||
sign [[gnu::pure]] (T val);
|
constexpr double sign (double);
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
21
maths.ipp
21
maths.ipp
@ -50,10 +50,23 @@ pow (T x, unsigned y)
|
|||||||
///
|
///
|
||||||
/// This really needs to be inline for performance as it's used in a few inner
|
/// This really needs to be inline for performance as it's used in a few inner
|
||||||
/// loops where the possibility of a function call is a deal breaker.
|
/// loops where the possibility of a function call is a deal breaker.
|
||||||
template <typename T>
|
constexpr int
|
||||||
typename try_signed<T>::type
|
sign (int v)
|
||||||
sign (T val) {
|
{
|
||||||
return val >= 0 ? T{1} : T{-1};
|
return __builtin_signbitl (v) ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr float
|
||||||
|
sign (float v)
|
||||||
|
{
|
||||||
|
return __builtin_signbitf (v) ? -1.f : 1.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
constexpr double
|
||||||
|
sign (double v)
|
||||||
|
{
|
||||||
|
return __builtin_signbit (v) ? -1. : 1.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user