- Switched from Allman (BSD) to 1TBS (K&R)
Namespaces, Types, and Requires/Concepts still use Allman
This commit is contained in:
@@ -301,15 +301,17 @@ namespace fennec
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType>
|
||||
constexpr genType sign(genType x)
|
||||
{ return (x < genType(0) ? genType(-1) : genType(1)) * static_cast<genType>(x != 0); } // reduces to cmove
|
||||
constexpr genType sign(genType x) {
|
||||
return (x < genType(0) ? genType(-1) : genType(1)) * static_cast<genType>(x != 0); // reduces to cmove
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> sign(const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::sign(x[i]) ...); }
|
||||
constexpr vector<genType, i...> sign(const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::sign(x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
// Absolute Value ======================================================================================================
|
||||
@@ -323,15 +325,17 @@ constexpr vector<genType, i...> sign(const vector<genType, i...>& x)
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType>
|
||||
constexpr genType abs(genType x)
|
||||
{ return x * fennec::sign(x); }
|
||||
constexpr genType abs(genType x) {
|
||||
return x * fennec::sign(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> abs(const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::abs(x[i]) ...); }
|
||||
constexpr vector<genType, i...> abs(const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::abs(x[i]) ...);
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
@@ -355,15 +359,17 @@ constexpr vector<genType, i...> abs(const vector<genType, i...>& x)
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType>
|
||||
constexpr genType floor(genType x)
|
||||
{ return ::floor(x); }
|
||||
constexpr genType floor(genType x) {
|
||||
return ::floor(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> floor(const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::floor(x[i]) ...); }
|
||||
constexpr vector<genType, i...> floor(const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::floor(x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -378,15 +384,17 @@ constexpr vector<genType, i...> floor(const vector<genType, i...>& x)
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType>
|
||||
constexpr genType ceil(genType x)
|
||||
{ return ::ceil(x); }
|
||||
constexpr genType ceil(genType x) {
|
||||
return ::ceil(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> ceil(const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::ceil(x[i]) ...); }
|
||||
constexpr vector<genType, i...> ceil(const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::ceil(x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -401,15 +409,17 @@ constexpr vector<genType, i...> ceil(const vector<genType, i...>& x)
|
||||
/// \f$\text{round}(x) = \text{sgn}(x) \cdot \lfloor \left| x \right| + 0.5 \rfloor\f$<br> <br>
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType> constexpr genType round(genType x)
|
||||
{ return ::round(x); }
|
||||
template<typename genType> constexpr genType round(genType x) {
|
||||
return ::round(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> round(const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::round(x[i]) ...); }
|
||||
constexpr vector<genType, i...> round(const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::round(x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -424,15 +434,17 @@ constexpr vector<genType, i...> round(const vector<genType, i...>& x)
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType>
|
||||
constexpr genType trunc(genType x)
|
||||
{ return ::trunc(x); }
|
||||
constexpr genType trunc(genType x) {
|
||||
return ::trunc(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> trunc(const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::trunc(x[i]) ...); }
|
||||
constexpr vector<genType, i...> trunc(const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::trunc(x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -449,17 +461,7 @@ constexpr vector<genType, i...> trunc(const vector<genType, i...>& x)
|
||||
///
|
||||
/// \param x input value
|
||||
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)
|
||||
// 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);
|
||||
constexpr genType roundEven(genType x) {
|
||||
static const genType e = std::numeric_limits<genType>::epsilon();
|
||||
int I = static_cast<int>(x);
|
||||
genType i = static_cast<genType>(I);
|
||||
@@ -469,13 +471,25 @@ constexpr genType roundEven(genType x)
|
||||
|
||||
bool dir = (I % 2);
|
||||
return dir ? i + 1 : i;
|
||||
|
||||
// Older version that generates significantly more branching and asm instructions
|
||||
//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; // This will cause a branch in most circumstances
|
||||
//return i + static_cast<genType>(up);
|
||||
}
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> roundEven(const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::roundEven(x[i]) ...); }
|
||||
constexpr vector<genType, i...> roundEven(const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::roundEven(x[i]) ...);
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
@@ -498,16 +512,17 @@ constexpr vector<genType, i...> roundEven(const vector<genType, i...>& x)
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType>
|
||||
constexpr genType fract(genType x)
|
||||
{ return x - ::floor(x); }
|
||||
constexpr genType fract(genType x) {
|
||||
return x - ::floor(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> fract(const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::fract(x[i]) ...); }
|
||||
|
||||
constexpr vector<genType, i...> fract(const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::fract(x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
// Mod =================================================================================================================
|
||||
@@ -522,20 +537,22 @@ constexpr vector<genType, i...> fract(const vector<genType, i...>& x)
|
||||
/// \param x dividend
|
||||
/// \param y divisor
|
||||
template<typename genType>
|
||||
constexpr genType mod(genType x, genType y)
|
||||
{ return x - y * fennec::floor(x / y); }
|
||||
constexpr genType mod(genType x, genType y) {
|
||||
return x - y * fennec::floor(x / y);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> mod(const vector<genType, i...>& x, genType y)
|
||||
{ return x - y * fennec::floor(x / y); }
|
||||
constexpr vector<genType, i...> mod(const vector<genType, i...>& x, genType y) {
|
||||
return x - y * fennec::floor(x / y);
|
||||
}
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> mod(const vector<genType, i...>& x, const vector<genType, i...>& y)
|
||||
{ return x - y * fennec::floor(x / y); }
|
||||
|
||||
constexpr vector<genType, i...> mod(const vector<genType, i...>& x, const vector<genType, i...>& y) {
|
||||
return x - y * fennec::floor(x / y);
|
||||
}
|
||||
|
||||
|
||||
// ModF ================================================================================================================
|
||||
@@ -550,16 +567,17 @@ constexpr vector<genType, i...> mod(const vector<genType, i...>& x, const vector
|
||||
/// \param x input value
|
||||
/// \param i integral out
|
||||
template<typename genType>
|
||||
constexpr genType modf(genType x, genType& i)
|
||||
{ i = fennec::floor(x); return fennec::fract(x); }
|
||||
constexpr genType modf(genType x, genType& i) {
|
||||
i = fennec::floor(x); return fennec::fract(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> modf(const vector<genType, i...>& x, vector<genType, i...>& I)
|
||||
{ I = fennec::floor(x); return fennec::fract(x); }
|
||||
|
||||
constexpr vector<genType, i...> modf(const vector<genType, i...>& x, vector<genType, i...>& I) {
|
||||
I = fennec::floor(x); return fennec::fract(x);
|
||||
}
|
||||
|
||||
|
||||
// Is NaN ==============================================================================================================
|
||||
@@ -578,16 +596,17 @@ constexpr vector<genType, i...> modf(const vector<genType, i...>& x, vector<genT
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType, typename genBType = bool_t> requires(is_bool_v<genBType>)
|
||||
constexpr genBType isnan(genType x)
|
||||
{ return ::isnanf(x); }
|
||||
constexpr genBType isnan(genType x) {
|
||||
return ::isnanf(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, typename genBType = bool_t, size_t...i> requires(is_bool_v<genBType>)
|
||||
constexpr vector<genBType, i...> isnan(const vector<genType, i...>& x)
|
||||
{ return vector<genBType, i...>(fennec::isnan(x[i]) ...); }
|
||||
|
||||
constexpr vector<genBType, i...> isnan(const vector<genType, i...>& x) {
|
||||
return vector<genBType, i...>(fennec::isnan(x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
// Is Inf ==============================================================================================================
|
||||
@@ -601,15 +620,17 @@ constexpr vector<genBType, i...> isnan(const vector<genType, i...>& x)
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType, typename genBType = bool_t> requires(is_bool_v<genBType>)
|
||||
constexpr genBType isinf(genType x)
|
||||
{ return ::isinff(x); }
|
||||
constexpr genBType isinf(genType x) {
|
||||
return ::isinff(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, typename genBType = bool_t, size_t...i> requires(is_bool_v<genBType>)
|
||||
constexpr vector<genBType, i...> isinf(const vector<genType, i...>& x)
|
||||
{ return vector<genBType, i...>(fennec::isinf(x[i]) ...); }
|
||||
constexpr vector<genBType, i...> isinf(const vector<genType, i...>& x) {
|
||||
return vector<genBType, i...>(fennec::isinf(x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -618,8 +639,10 @@ constexpr vector<genBType, i...> isinf(const vector<genType, i...>& x)
|
||||
///
|
||||
/// \copydetails fennec::floatBitsToUint(fennec::genFType)
|
||||
template<typename genType, typename genIType = int_t> requires(is_floating_point_v<genType> and is_integral_v<genIType> and is_signed_v<genIType> and sizeof(genType) == sizeof(genIType))
|
||||
constexpr genIType floatBitsToInt(genType x)
|
||||
{ return fennec::bit_cast<genIType>(x); }
|
||||
constexpr genIType floatBitsToInt(genType x) {
|
||||
return fennec::bit_cast<genIType>(x);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// \brief Returns a signed or unsigned integer value representing the encoding of a floating-point value.
|
||||
@@ -638,14 +661,17 @@ constexpr genIType floatBitsToInt(genType x)
|
||||
///
|
||||
/// \param x value to convert
|
||||
template<typename genType, typename genUType = uint_t> requires(is_floating_point_v<genType> and is_integral_v<genUType> and is_unsigned_v<genUType> and sizeof(genType) == sizeof(genUType))
|
||||
constexpr genUType floatBitsToUint(genType x)
|
||||
{ return fennec::bit_cast<genUType>(x); }
|
||||
constexpr genUType floatBitsToUint(genType x) {
|
||||
return fennec::bit_cast<genUType>(x);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// \copydetails fennec::uintBitsToFloat(fennec::genUType)
|
||||
template<typename genType = float_t, typename genIType = int_t> requires(is_floating_point_v<genType> and is_integral_v<genIType> and is_signed_v<genIType> and sizeof(genType) == sizeof(genIType))
|
||||
constexpr genType intBitsToFloat(genIType x)
|
||||
{ return fennec::bit_cast<genType>(x); }
|
||||
constexpr genType intBitsToFloat(genIType x) {
|
||||
return fennec::bit_cast<genType>(x);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
@@ -663,27 +689,32 @@ constexpr genType intBitsToFloat(genIType x)
|
||||
///
|
||||
/// \param x value to convert
|
||||
template<typename genType = float_t, typename genUType = uint_t> requires(is_floating_point_v<genType> and is_integral_v<genUType> and is_unsigned_v<genUType> and sizeof(genType) == sizeof(genUType))
|
||||
constexpr genType uintBitsToFloat(genUType x)
|
||||
{ return fennec::bit_cast<genType>(x); }
|
||||
constexpr genType uintBitsToFloat(genUType x) {
|
||||
return fennec::bit_cast<genType>(x);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType = float_t, typename genIType = int_t, size_t...i> requires(is_floating_point_v<genType> and is_integral_v<genIType> and is_signed_v<genIType> and sizeof(genType) == sizeof(genIType))
|
||||
constexpr vector<genIType, i...> floatBitsToInt(const vector<genType, i...>& x)
|
||||
{ return vector<genIType, i...>(fennec::bit_cast<genIType>(x[i])...); }
|
||||
constexpr vector<genIType, i...> floatBitsToInt(const vector<genType, i...>& x) {
|
||||
return vector<genIType, i...>(fennec::bit_cast<genIType>(x[i])...);
|
||||
}
|
||||
|
||||
template<typename genType = float_t, typename genUType = uint_t, size_t...i> requires(is_floating_point_v<genType> and is_integral_v<genUType> and is_unsigned_v<genUType> and sizeof(genType) == sizeof(genUType))
|
||||
constexpr vector<genUType, i...> floatBitsToUint(const vector<genType, i...>& x)
|
||||
{ return vector<genUType, i...>(fennec::bit_cast<genUType>(x[i])...); }
|
||||
constexpr vector<genUType, i...> floatBitsToUint(const vector<genType, i...>& x) {
|
||||
return vector<genUType, i...>(fennec::bit_cast<genUType>(x[i])...);
|
||||
}
|
||||
|
||||
template<typename genType = float_t, typename genIType = int_t, size_t...i> requires(is_floating_point_v<genType> and is_integral_v<genIType> and is_signed_v<genIType> and sizeof(genType) == sizeof(genIType))
|
||||
constexpr vector<genType, i...> intBitsToFloat(const vector<genIType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::bit_cast<genType>(x[i]) ...); }
|
||||
constexpr vector<genType, i...> intBitsToFloat(const vector<genIType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::bit_cast<genType>(x[i]) ...);
|
||||
}
|
||||
|
||||
template<typename genType = float_t, typename genUType = uint_t, size_t...i> requires(is_floating_point_v<genType> and is_integral_v<genUType> and is_unsigned_v<genUType> and sizeof(genType) == sizeof(genUType))
|
||||
constexpr vector<genType, i...> uintBitsToFloat(const vector<genUType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::bit_cast<genType>(x[i]) ...); }
|
||||
constexpr vector<genType, i...> uintBitsToFloat(const vector<genUType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::bit_cast<genType>(x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -700,15 +731,17 @@ constexpr vector<genType, i...> uintBitsToFloat(const vector<genUType, i...>& x)
|
||||
/// \param b the multiplier
|
||||
/// \param c the addend
|
||||
template<typename genType>
|
||||
constexpr genType fma(genType a, genType b, genType c)
|
||||
{ return genType(::fma(a, b, c)); }
|
||||
constexpr genType fma(genType a, genType b, genType c) {
|
||||
return genType(::fma(a, b, c));
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> fma(const vector<genType, i...>& a, const vector<genType, i...>& b, const vector<genType, i...>& c)
|
||||
{ return vector<genType, i...>(fennec::fma(a[i], b[i], c[i]) ...); }
|
||||
constexpr vector<genType, i...> fma(const vector<genType, i...>& a, const vector<genType, i...>& b, const vector<genType, i...>& c) {
|
||||
return vector<genType, i...>(fennec::fma(a[i], b[i], c[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -729,15 +762,17 @@ constexpr vector<genType, i...> fma(const vector<genType, i...>& a, const vector
|
||||
/// \param x The floating-point value to split
|
||||
/// \param exp The variable to store the exponent in
|
||||
template<typename genType, typename genIType = int_t> requires(is_integral_v<genIType>)
|
||||
constexpr genType frexp(genType x, genIType& exp)
|
||||
{ return ::frexp(x, &exp); }
|
||||
constexpr genType frexp(genType x, genIType& exp) {
|
||||
return ::frexp(x, &exp);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, typename genIType = int_t, size_t...i> requires(is_integral_v<genIType>)
|
||||
constexpr vector<genType, i...> frexp(const vector<genType, i...>& x, vector<genIType, i...>& exp)
|
||||
{ return vector<genType, i...>(fennec::frexp(x[i], exp[i])...); }
|
||||
constexpr vector<genType, i...> frexp(const vector<genType, i...>& x, vector<genIType, i...>& exp) {
|
||||
return vector<genType, i...>(fennec::frexp(x[i], exp[i])...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -760,15 +795,17 @@ constexpr vector<genType, i...> frexp(const vector<genType, i...>& x, vector<gen
|
||||
/// \param x The significand
|
||||
/// \param exp The exponent
|
||||
template<typename genType, typename genIType = int_t> requires(is_integral_v<genIType>)
|
||||
constexpr genType ldexp(genType x, genIType exp)
|
||||
{ return ::ldexp(x, exp); }
|
||||
constexpr genType ldexp(genType x, genIType exp) {
|
||||
return ::ldexp(x, exp);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, typename genIType = int_t, size_t...i> requires(is_integral_v<genIType>)
|
||||
constexpr vector<genType, i...> ldexp(const vector<genType, i...>& x, const vector<genType, i...>& exp)
|
||||
{ return vector<genType, i...>(fennec::ldexp(x[i], exp[i])...); }
|
||||
constexpr vector<genType, i...> ldexp(const vector<genType, i...>& x, const vector<genType, i...>& exp) {
|
||||
return vector<genType, i...>(fennec::ldexp(x[i], exp[i])...);
|
||||
}
|
||||
|
||||
|
||||
/// @}
|
||||
@@ -793,24 +830,27 @@ constexpr vector<genType, i...> ldexp(const vector<genType, i...>& x, const vect
|
||||
/// \param x input value \f$x\f$
|
||||
/// \param y input value \f$y\f$
|
||||
template<typename genType>
|
||||
constexpr genType min(genType x, genType y)
|
||||
{ return (y < x) ? y : x; }
|
||||
constexpr genType min(genType x, genType y) {
|
||||
return (y < x) ? y : x;
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> min(genType x, const vector<genType, i...>& y)
|
||||
{ return vector<genType, i...>(fennec::min(x, y[i]) ...); }
|
||||
constexpr vector<genType, i...> min(genType x, const vector<genType, i...>& y) {
|
||||
return vector<genType, i...>(fennec::min(x, y[i]) ...);
|
||||
}
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> min(const vector<genType, i...>& x, genType y)
|
||||
{ return vector<genType, i...>(fennec::min(x[i], y) ...); }
|
||||
constexpr vector<genType, i...> min(const vector<genType, i...>& x, genType y) {
|
||||
return vector<genType, i...>(fennec::min(x[i], y) ...);
|
||||
}
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> min(const vector<genType, i...>& x, const vector<genType, i...>& y)
|
||||
{ return vector<genType, i...>(fennec::min(x[i], y[i]) ...); }
|
||||
|
||||
constexpr vector<genType, i...> min(const vector<genType, i...>& x, const vector<genType, i...>& y) {
|
||||
return vector<genType, i...>(fennec::min(x[i], y[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
// Max =================================================================================================================
|
||||
@@ -825,23 +865,27 @@ constexpr vector<genType, i...> min(const vector<genType, i...>& x, const vector
|
||||
/// \param x first input value
|
||||
/// \param y second input value
|
||||
template<typename genType>
|
||||
constexpr genType max(genType x, genType y)
|
||||
{ return (x < y) ? y : x; }
|
||||
constexpr genType max(genType x, genType y) {
|
||||
return (x < y) ? y : x;
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> max(genType x, const vector<genType, i...>& y)
|
||||
{ return vector<genType, i...>(fennec::max(x, y[i]) ...); }
|
||||
constexpr vector<genType, i...> max(genType x, const vector<genType, i...>& y) {
|
||||
return vector<genType, i...>(fennec::max(x, y[i]) ...);
|
||||
}
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> max(const vector<genType, i...>& x, genType y)
|
||||
{ return vector<genType, i...>(fennec::max(x[i], y) ...); }
|
||||
constexpr vector<genType, i...> max(const vector<genType, i...>& x, genType y) {
|
||||
return vector<genType, i...>(fennec::max(x[i], y) ...);
|
||||
}
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> max(const vector<genType, i...>& x, const vector<genType, i...>& y)
|
||||
{ return vector<genType, i...>(fennec::max(x[i], y[i]) ...); }
|
||||
constexpr vector<genType, i...> max(const vector<genType, i...>& x, const vector<genType, i...>& y) {
|
||||
return vector<genType, i...>(fennec::max(x[i], y[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
// Clamp ===============================================================================================================
|
||||
@@ -857,19 +901,22 @@ constexpr vector<genType, i...> max(const vector<genType, i...>& x, const vector
|
||||
/// \param minVal minimum value
|
||||
/// \param maxVal maximum value
|
||||
template<typename genType>
|
||||
constexpr genType clamp(genType x, genType minVal, genType maxVal)
|
||||
{ return min(max(x, minVal), maxVal); }
|
||||
constexpr genType clamp(genType x, genType minVal, genType maxVal) {
|
||||
return min(max(x, minVal), maxVal);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> clamp(const vector<genType, i...>& x, genType minVal, genType maxVal)
|
||||
{ return vector<genType, i...>(fennec::min(fennec::max(x[i], minVal), maxVal)...); }
|
||||
constexpr vector<genType, i...> clamp(const vector<genType, i...>& x, genType minVal, genType maxVal) {
|
||||
return vector<genType, i...>(fennec::min(fennec::max(x[i], minVal), maxVal)...);
|
||||
}
|
||||
|
||||
template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> clamp(const vector<genType, i...>& x, const vector<genType, i...>& minVal, const vector<genType, i...>& maxVal)
|
||||
{ return vector<genType, i...>(fennec::min(fennec::max(x[i], minVal[i]), maxVal[i])...); }
|
||||
constexpr vector<genType, i...> clamp(const vector<genType, i...>& x, const vector<genType, i...>& minVal, const vector<genType, i...>& maxVal) {
|
||||
return vector<genType, i...>(fennec::min(fennec::max(x[i], minVal[i]), maxVal[i])...);
|
||||
}
|
||||
|
||||
|
||||
/// @}
|
||||
@@ -894,19 +941,22 @@ constexpr vector<genType, i...> clamp(const vector<genType, i...>& x, const vect
|
||||
/// \param edge The \f$x\f$ coordinate of the discontinuity
|
||||
/// \param x The coordinate of the sample location
|
||||
template<typename genType> requires(is_floating_point_v<genType>)
|
||||
constexpr genType step(genType edge, genType x)
|
||||
{ return static_cast<genType>(not(x < edge)); }
|
||||
constexpr genType step(genType edge, genType x) {
|
||||
return static_cast<genType>(not(x < edge));
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i> requires(is_floating_point_v<genType>)
|
||||
constexpr vector<genType, i...> step(genType edge, const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::step(edge, x[i]) ...); }
|
||||
constexpr vector<genType, i...> step(genType edge, const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::step(edge, x[i]) ...);
|
||||
}
|
||||
|
||||
template<typename genType, size_t...i> requires(is_floating_point_v<genType>)
|
||||
constexpr vector<genType, i...> step(const vector<genType, i...>& edge, const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::step(edge[i], x[i]) ...); }
|
||||
constexpr vector<genType, i...> step(const vector<genType, i...>& edge, const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::step(edge[i], x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
// Smoothstep ==========================================================================================================
|
||||
@@ -932,19 +982,22 @@ constexpr vector<genType, i...> step(const vector<genType, i...>& edge, const ve
|
||||
/// \param edge1 \f$x\f$ value where the function returns \f$1.0\f$
|
||||
/// \param x \f$x\f$ coordinate input
|
||||
template<typename genType> requires(is_floating_point_v<genType>)
|
||||
constexpr genType smoothstep(genType edge0, genType edge1, genType x)
|
||||
{ genType t = fennec::clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f); return t * t * (3 - 2 * t); }
|
||||
constexpr genType smoothstep(genType edge0, genType edge1, genType x) {
|
||||
genType t = fennec::clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f); return t * t * (3 - 2 * t);
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i> requires(is_floating_point_v<genType>)
|
||||
constexpr vector<genType, i...> smoothstep(genType edge0, genType edge1, const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::smoothstep(edge0, edge1, x[i]) ...); }
|
||||
constexpr vector<genType, i...> smoothstep(genType edge0, genType edge1, const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::smoothstep(edge0, edge1, x[i]) ...);
|
||||
}
|
||||
|
||||
template<typename genType, size_t...i> requires(is_floating_point_v<genType>)
|
||||
constexpr vector<genType, i...> smoothstep(const vector<genType, i...>& edge0, const vector<genType, i...>& edge1, const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::smoothstep(edge0[i], edge1[i], x[i]) ...); }
|
||||
constexpr vector<genType, i...> smoothstep(const vector<genType, i...>& edge0, const vector<genType, i...>& edge1, const vector<genType, i...>& x) {
|
||||
return vector<genType, i...>(fennec::smoothstep(edge0[i], edge1[i], x[i]) ...);
|
||||
}
|
||||
|
||||
|
||||
// Mix =================================================================================================================
|
||||
@@ -963,18 +1016,21 @@ constexpr vector<genType, i...> smoothstep(const vector<genType, i...>& edge0, c
|
||||
/// \param y Second value
|
||||
/// \param a Interpolant
|
||||
template<typename genType> requires(is_floating_point_v<genType>)
|
||||
constexpr genType mix(genType x, genType y, genType a)
|
||||
{ return x * (genType(1.0) - a) + y * a; }
|
||||
constexpr genType mix(genType x, genType y, genType a) {
|
||||
return x * (genType(1.0) - a) + y * a;
|
||||
}
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, size_t...i> requires(is_floating_point_v<genType>)
|
||||
constexpr vector<genType, i...> mix(const vector<genType, i...>& x, const vector<genType, i...>& y, genType a)
|
||||
{ return x * (genType(1.0) - a) + y * a; }
|
||||
constexpr vector<genType, i...> mix(const vector<genType, i...>& x, const vector<genType, i...>& y, genType a) {
|
||||
return x * (genType(1.0) - a) + y * a;
|
||||
}
|
||||
|
||||
template<typename genType, size_t...i> requires(is_floating_point_v<genType>)
|
||||
constexpr vector<genType, i...> mix(const vector<genType, i...>& x, const vector<genType, i...>& y, const vector<genType, i...>& a)
|
||||
{ return x * (genType(1.0) - a) + y * a; }
|
||||
constexpr vector<genType, i...> mix(const vector<genType, i...>& x, const vector<genType, i...>& y, const vector<genType, i...>& a) {
|
||||
return x * (genType(1.0) - a) + y * a;
|
||||
}
|
||||
|
||||
|
||||
// Mix (Bool) ==========================================================================================================
|
||||
@@ -995,24 +1051,28 @@ constexpr vector<genType, i...> mix(const vector<genType, i...>& x, const vector
|
||||
/// \param y False Value
|
||||
/// \param a Boolean Value
|
||||
template<typename genType, typename genBType = bool_t> requires(is_bool_v<genBType> and is_floating_point_v<genType>)
|
||||
constexpr genType mix(genType x, genType y, genBType a)
|
||||
{ return a ? y : x; }
|
||||
constexpr genType mix(genType x, genType y, genBType a) {
|
||||
return a ? y : x;
|
||||
}
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
|
||||
template<typename genType, typename genBType = bool_t, size_t...i> requires(is_bool_v<genBType> and is_floating_point_v<genType>)
|
||||
constexpr vector<genType, i...> mix(const vector<genType, i...>& x, const vector<genType, i...>& y, genBType a)
|
||||
{ return genDType((a ? y[i] : x[i])...); }
|
||||
constexpr vector<genType, i...> mix(const vector<genType, i...>& x, const vector<genType, i...>& y, genBType a) {
|
||||
return genDType((a ? y[i] : x[i])...);
|
||||
}
|
||||
|
||||
|
||||
template<typename genBType = bool_t, size_t...i> requires(is_bool_v<genBType>)
|
||||
constexpr vector<genBType, i...> mix(const vector<genBType, i...>& x, const vector<genBType, i...>& y, const vector<genBType, i...>& a)
|
||||
{ return genBType((a[i] ? y[i] : x[i])...); }
|
||||
constexpr vector<genBType, i...> mix(const vector<genBType, i...>& x, const vector<genBType, i...>& y, const vector<genBType, i...>& a) {
|
||||
return genBType((a[i] ? y[i] : x[i])...);
|
||||
}
|
||||
|
||||
template<typename genType, typename genBType = bool_t, size_t...i> requires(is_bool_v<genBType> and is_floating_point_v<genType>)
|
||||
constexpr vector<genType, i...> mix(const vector<genType, i...>& x, const vector<genType, i...>& y, const vector<genBType, i...>& a)
|
||||
{ return genDType((a[i] ? y[i] : x[i])...); }
|
||||
constexpr vector<genType, i...> mix(const vector<genType, i...>& x, const vector<genType, i...>& y, const vector<genBType, i...>& a) {
|
||||
return genDType((a[i] ? y[i] : x[i])...);
|
||||
}
|
||||
|
||||
|
||||
/// @}
|
||||
|
||||
Reference in New Issue
Block a user