Fixes for MSVC
This commit is contained in:
@@ -273,6 +273,11 @@
|
||||
|
||||
#include <fennec/math/vector.h>
|
||||
|
||||
#if _MSC_VER
|
||||
#define isnanf(x) isnan(x)
|
||||
#define isinff(x) isinf(x)
|
||||
#endif
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
@@ -408,31 +413,6 @@ constexpr vector<genType, i...> round(const vector<genType, i...>& x)
|
||||
|
||||
|
||||
|
||||
// Round Even ==========================================================================================================
|
||||
|
||||
///
|
||||
/// \brief Returns a value equal to the nearest integer. In C++, a fractional part of \f$0.5\f$ will always
|
||||
/// round to the nearest even integer.
|
||||
///
|
||||
/// \returns a value equal to the nearest integer.<br> <br>
|
||||
/// \details In C++, a fractional part of \f$0.5\f$ will always round to the nearest even integer.<br> <br>
|
||||
/// We can express this as,<br> <br>
|
||||
/// \f$\text{roundEven}() = \begin{cases}\lfloor{x}\rfloor + \text{mod}(\lfloor{x}\rfloor, 2.0) & \text{fract}(x) = 0.5, \\ \text{round}(x) \end{cases}\f$<br> <br>
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType>
|
||||
constexpr genType roundEven(genType x)
|
||||
{ return ::roundeven(x); }
|
||||
|
||||
|
||||
// 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]) ...); }
|
||||
|
||||
|
||||
|
||||
// Trunc ===============================================================================================================
|
||||
|
||||
///
|
||||
@@ -454,6 +434,40 @@ template<typename genType, size_t...i>
|
||||
constexpr vector<genType, i...> trunc(const vector<genType, i...>& x)
|
||||
{ return vector<genType, i...>(fennec::trunc(x[i]) ...); }
|
||||
|
||||
|
||||
|
||||
// Round Even ==========================================================================================================
|
||||
|
||||
///
|
||||
/// \brief Returns a value equal to the nearest integer. In C++, a fractional part of \f$0.5\f$ will always
|
||||
/// round to the nearest even integer.
|
||||
///
|
||||
/// \returns a value equal to the nearest integer.<br> <br>
|
||||
/// \details In C++, a fractional part of \f$0.5\f$ will always round to the nearest even integer.<br> <br>
|
||||
/// We can express this as,<br> <br>
|
||||
/// \f$\text{roundEven}() = \begin{cases}\lfloor{x}\rfloor + \text{mod}(\lfloor{x}\rfloor, 2.0) & \text{fract}(x) = 0.5, \\ \text{round}(x) \end{cases}\f$<br> <br>
|
||||
///
|
||||
/// \param x input value
|
||||
template<typename genType>
|
||||
constexpr genType roundEven(genType x)
|
||||
{
|
||||
const float e = numeric_limits<genType>::epsilon();
|
||||
float f = x - fennec::floor(x);
|
||||
if (fennec::abs(f - genType(0.5)) > e)
|
||||
return fennec::round(x);
|
||||
|
||||
float i = fennec::floor(x);
|
||||
float r = i / 2;
|
||||
bool up = r - fennec::floor(r) > e;
|
||||
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]) ...); }
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
@@ -678,7 +692,7 @@ constexpr vector<genType, i...> uintBitsToFloat(const vector<genUType, i...>& x)
|
||||
/// \param c the addend
|
||||
template<typename genType>
|
||||
constexpr genType fma(genType a, genType b, genType c)
|
||||
{ return ::fma(a, b, c); }
|
||||
{ return genType(::fma(a, b, c)); }
|
||||
|
||||
|
||||
// Vector Specializations ----------------------------------------------------------------------------------------------
|
||||
@@ -941,17 +955,17 @@ constexpr vector<genType, i...> smoothstep(const vector<genType, i...>& edge0, c
|
||||
/// \param a Interpolant
|
||||
template<typename genType> requires(is_floating_point_v<genType>)
|
||||
constexpr genType mix(genType x, genType y, genType a)
|
||||
{ return x * (1.0 - a) + y * 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 * (1.0 - a) + y * 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 * (1.0 - a) + y * a; }
|
||||
{ return x * (genType(1.0) - a) + y * a; }
|
||||
|
||||
|
||||
// Mix (Bool) ==========================================================================================================
|
||||
|
||||
Reference in New Issue
Block a user