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>
|
||||
typename try_signed<T>::type
|
||||
sign [[gnu::pure]] (T val);
|
||||
constexpr int sign (int);
|
||||
constexpr float sign (float);
|
||||
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
|
||||
/// loops where the possibility of a function call is a deal breaker.
|
||||
template <typename T>
|
||||
typename try_signed<T>::type
|
||||
sign (T val) {
|
||||
return val >= 0 ? T{1} : T{-1};
|
||||
constexpr int
|
||||
sign (int v)
|
||||
{
|
||||
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