Renamed P (for precision) template argument to Q (for qualifier)

This commit is contained in:
Christophe Riccio
2017-08-16 01:22:50 +02:00
parent e76fca75a0
commit faf1da52b7
176 changed files with 9392 additions and 9408 deletions

View File

@@ -151,17 +151,17 @@ namespace bitfieldReverse
return Result;
}
*/
template<glm::length_t L, typename T, glm::qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, T, P> bitfieldReverseLoop(glm::vec<L, T, P> const& v)
template<glm::length_t L, typename T, glm::qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> bitfieldReverseLoop(glm::vec<L, T, Q> const& v)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldReverse' only accept integer values");
glm::vec<L, T, P> Result(0);
glm::vec<L, T, Q> Result(0);
T const BitSize = static_cast<T>(sizeof(T) * 8);
for(T i = 0; i < BitSize; ++i)
{
glm::vec<L, T, P> const BitSet(v & (static_cast<T>(1) << i));
glm::vec<L, T, P> const BitFirst(BitSet >> i);
glm::vec<L, T, Q> const BitSet(v & (static_cast<T>(1) << i));
glm::vec<L, T, Q> const BitFirst(BitSet >> i);
Result |= BitFirst << (BitSize - 1 - i);
}
return Result;
@@ -197,8 +197,8 @@ namespace bitfieldReverse
template<bool EXEC = false>
struct compute_bitfieldReverseStep
{
template<glm::length_t L, typename T, glm::qualifier P>
GLM_FUNC_QUALIFIER static glm::vec<L, T, P> call(glm::vec<L, T, P> const& v, T, T)
template<glm::length_t L, typename T, glm::qualifier Q>
GLM_FUNC_QUALIFIER static glm::vec<L, T, Q> call(glm::vec<L, T, Q> const& v, T, T)
{
return v;
}
@@ -207,17 +207,17 @@ namespace bitfieldReverse
template<>
struct compute_bitfieldReverseStep<true>
{
template<glm::length_t L, typename T, glm::qualifier P>
GLM_FUNC_QUALIFIER static glm::vec<L, T, P> call(glm::vec<L, T, P> const& v, T Mask, T Shift)
template<glm::length_t L, typename T, glm::qualifier Q>
GLM_FUNC_QUALIFIER static glm::vec<L, T, Q> call(glm::vec<L, T, Q> const& v, T Mask, T Shift)
{
return (v & Mask) << Shift | (v & (~Mask)) >> Shift;
}
};
template<glm::length_t L, typename T, glm::qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, T, P> bitfieldReverseOps(glm::vec<L, T, P> const& v)
template<glm::length_t L, typename T, glm::qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> bitfieldReverseOps(glm::vec<L, T, Q> const& v)
{
glm::vec<L, T, P> x(v);
glm::vec<L, T, Q> x(v);
x = compute_bitfieldReverseStep<sizeof(T) * 8 >= 2>::call(x, T(0x5555555555555555ull), static_cast<T>( 1));
x = compute_bitfieldReverseStep<sizeof(T) * 8 >= 4>::call(x, T(0x3333333333333333ull), static_cast<T>( 2));
x = compute_bitfieldReverseStep<sizeof(T) * 8 >= 8>::call(x, T(0x0F0F0F0F0F0F0F0Full), static_cast<T>( 4));
@@ -1397,8 +1397,8 @@ namespace bitCount
template<bool EXEC = false>
struct compute_bitfieldBitCountStep
{
template<glm::length_t L, typename T, glm::qualifier P>
GLM_FUNC_QUALIFIER static glm::vec<L, T, P> call(glm::vec<L, T, P> const& v, T, T)
template<glm::length_t L, typename T, glm::qualifier Q>
GLM_FUNC_QUALIFIER static glm::vec<L, T, Q> call(glm::vec<L, T, Q> const& v, T, T)
{
return v;
}
@@ -1407,24 +1407,24 @@ namespace bitCount
template<>
struct compute_bitfieldBitCountStep<true>
{
template<glm::length_t L, typename T, glm::qualifier P>
GLM_FUNC_QUALIFIER static glm::vec<L, T, P> call(glm::vec<L, T, P> const& v, T Mask, T Shift)
template<glm::length_t L, typename T, glm::qualifier Q>
GLM_FUNC_QUALIFIER static glm::vec<L, T, Q> call(glm::vec<L, T, Q> const& v, T Mask, T Shift)
{
return (v & Mask) + ((v >> Shift) & Mask);
}
};
template<glm::length_t L, typename T, glm::qualifier P>
static glm::vec<L, int, P> bitCount_bitfield(glm::vec<L, T, P> const& v)
template<glm::length_t L, typename T, glm::qualifier Q>
static glm::vec<L, int, Q> bitCount_bitfield(glm::vec<L, T, Q> const& v)
{
glm::vec<L, typename glm::detail::make_unsigned<T>::type, P> x(*reinterpret_cast<glm::vec<L, typename glm::detail::make_unsigned<T>::type, P> const *>(&v));
glm::vec<L, typename glm::detail::make_unsigned<T>::type, Q> x(*reinterpret_cast<glm::vec<L, typename glm::detail::make_unsigned<T>::type, Q> const *>(&v));
x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 2>::call(x, typename glm::detail::make_unsigned<T>::type(0x5555555555555555ull), typename glm::detail::make_unsigned<T>::type( 1));
x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 4>::call(x, typename glm::detail::make_unsigned<T>::type(0x3333333333333333ull), typename glm::detail::make_unsigned<T>::type( 2));
x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 8>::call(x, typename glm::detail::make_unsigned<T>::type(0x0F0F0F0F0F0F0F0Full), typename glm::detail::make_unsigned<T>::type( 4));
x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 16>::call(x, typename glm::detail::make_unsigned<T>::type(0x00FF00FF00FF00FFull), typename glm::detail::make_unsigned<T>::type( 8));
x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 32>::call(x, typename glm::detail::make_unsigned<T>::type(0x0000FFFF0000FFFFull), typename glm::detail::make_unsigned<T>::type(16));
x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 64>::call(x, typename glm::detail::make_unsigned<T>::type(0x00000000FFFFFFFFull), typename glm::detail::make_unsigned<T>::type(32));
return glm::vec<L, int, P>(x);
return glm::vec<L, int, Q>(x);
}
template<typename genType>

View File

@@ -174,16 +174,17 @@ namespace fastAtan
namespace taylorCos
{
using glm::qualifier;
using glm::length_t;
glm::vec4 const AngleShift(0.0f, glm::half_pi<float>(), glm::pi<float>(), glm::three_over_two_pi<float>());
template<glm::length_t L, typename T, qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, T, P> taylorSeriesNewCos(glm::vec<L, T, P> const& x)
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> taylorSeriesNewCos(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, P> const Powed2(x * x);
glm::vec<L, T, P> const Powed4(Powed2 * Powed2);
glm::vec<L, T, P> const Powed6(Powed4 * Powed2);
glm::vec<L, T, P> const Powed8(Powed4 * Powed4);
glm::vec<L, T, Q> const Powed2(x * x);
glm::vec<L, T, Q> const Powed4(Powed2 * Powed2);
glm::vec<L, T, Q> const Powed6(Powed4 * Powed2);
glm::vec<L, T, Q> const Powed8(Powed4 * Powed4);
return static_cast<T>(1)
- Powed2 * static_cast<T>(0.5)
@@ -192,12 +193,12 @@ namespace taylorCos
+ Powed8 * static_cast<T>(2.4801587301587301587301587301587e-5);
}
template<glm::length_t L, typename T, qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, T, P> taylorSeriesNewCos6(glm::vec<L, T, P> const& x)
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> taylorSeriesNewCos6(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, P> const Powed2(x * x);
glm::vec<L, T, P> const Powed4(Powed2 * Powed2);
glm::vec<L, T, P> const Powed6(Powed4 * Powed2);
glm::vec<L, T, Q> const Powed2(x * x);
glm::vec<L, T, Q> const Powed4(Powed2 * Powed2);
glm::vec<L, T, Q> const Powed6(Powed4 * Powed2);
return static_cast<T>(1)
- Powed2 * static_cast<T>(0.5)
@@ -205,8 +206,8 @@ namespace taylorCos
- Powed6 * static_cast<T>(0.00138888888888888888888888888889);
}
template<glm::length_t L, qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, float, P> fastAbs(glm::vec<L, float, P> x)
template<glm::length_t L, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, float, Q> fastAbs(glm::vec<L, float, Q> x)
{
int* Pointer = reinterpret_cast<int*>(&x[0]);
Pointer[0] &= 0x7fffffff;
@@ -216,17 +217,17 @@ namespace taylorCos
return x;
}
template<glm::length_t L, typename T, glm::qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, T, P> fastCosNew(glm::vec<L, T, P> const& x)
template<glm::length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> fastCosNew(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, P> const Angle0_PI(fastAbs(fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
glm::vec<L, T, Q> const Angle0_PI(fastAbs(fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
return taylorSeriesNewCos6(x);
/*
vec<L, bool, P> const FirstQuarterPi(lessThanEqual(Angle0_PI, vec<L, T, P>(glm::half_pi<T>())));
vec<L, bool, Q> const FirstQuarterPi(lessThanEqual(Angle0_PI, vec<L, T, Q>(glm::half_pi<T>())));
vec<L, T, P> const RevertAngle(mix(vec<L, T, P>(glm::pi<T>()), vec<L, T, P>(0), FirstQuarterPi));
vec<L, T, P> const ReturnSign(mix(vec<L, T, P>(-1), vec<L, T, P>(1), FirstQuarterPi));
vec<L, T, P> const SectionAngle(RevertAngle - Angle0_PI);
vec<L, T, Q> const RevertAngle(mix(vec<L, T, Q>(glm::pi<T>()), vec<L, T, Q>(0), FirstQuarterPi));
vec<L, T, Q> const ReturnSign(mix(vec<L, T, Q>(-1), vec<L, T, Q>(1), FirstQuarterPi));
vec<L, T, Q> const SectionAngle(RevertAngle - Angle0_PI);
return ReturnSign * taylorSeriesNewCos(SectionAngle);
*/
@@ -254,21 +255,21 @@ namespace taylorCos
return Error;
}
template<glm::length_t L, typename T, qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, T, P> deterministic_fmod(glm::vec<L, T, P> const& x, T y)
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> deterministic_fmod(glm::vec<L, T, Q> const& x, T y)
{
return x - y * trunc(x / y);
}
template<glm::length_t L, typename T, qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, T, P> fastCosDeterminisctic(glm::vec<L, T, P> const& x)
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> fastCosDeterminisctic(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, P> const Angle0_PI(abs(deterministic_fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
glm::vec<L, bool, P> const FirstQuarterPi(lessThanEqual(Angle0_PI, glm::vec<L, T, P>(glm::half_pi<T>())));
glm::vec<L, T, Q> const Angle0_PI(abs(deterministic_fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
glm::vec<L, bool, Q> const FirstQuarterPi(lessThanEqual(Angle0_PI, glm::vec<L, T, Q>(glm::half_pi<T>())));
glm::vec<L, T, P> const RevertAngle(mix(glm::vec<L, T, P>(glm::pi<T>()), glm::vec<L, T, P>(0), FirstQuarterPi));
glm::vec<L, T, P> const ReturnSign(mix(glm::vec<L, T, P>(-1), glm::vec<L, T, P>(1), FirstQuarterPi));
glm::vec<L, T, P> const SectionAngle(RevertAngle - Angle0_PI);
glm::vec<L, T, Q> const RevertAngle(mix(glm::vec<L, T, Q>(glm::pi<T>()), glm::vec<L, T, Q>(0), FirstQuarterPi));
glm::vec<L, T, Q> const ReturnSign(mix(glm::vec<L, T, Q>(-1), glm::vec<L, T, Q>(1), FirstQuarterPi));
glm::vec<L, T, Q> const SectionAngle(RevertAngle - Angle0_PI);
return ReturnSign * taylorSeriesNewCos(SectionAngle);
}
@@ -295,8 +296,8 @@ namespace taylorCos
return Error;
}
template<glm::length_t L, typename T, qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, T, P> taylorSeriesRefCos(glm::vec<L, T, P> const& x)
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> taylorSeriesRefCos(glm::vec<L, T, Q> const& x)
{
return static_cast<T>(1)
- (x * x) / glm::factorial(static_cast<T>(2))
@@ -305,17 +306,17 @@ namespace taylorCos
+ (x * x * x * x * x * x * x * x) / glm::factorial(static_cast<T>(8));
}
template<glm::length_t L, typename T, qualifier P>
GLM_FUNC_QUALIFIER glm::vec<L, T, P> fastRefCos(glm::vec<L, T, P> const& x)
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> fastRefCos(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, P> const Angle0_PI(glm::abs(fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
glm::vec<L, T, Q> const Angle0_PI(glm::abs(fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
// return taylorSeriesRefCos(Angle0_PI);
glm::vec<L, bool, P> const FirstQuarterPi(lessThanEqual(Angle0_PI, glm::vec<L, T, P>(glm::half_pi<T>())));
glm::vec<L, bool, Q> const FirstQuarterPi(lessThanEqual(Angle0_PI, glm::vec<L, T, Q>(glm::half_pi<T>())));
glm::vec<L, T, P> const RevertAngle(mix(glm::vec<L, T, P>(glm::pi<T>()), glm::vec<L, T, P>(0), FirstQuarterPi));
glm::vec<L, T, P> const ReturnSign(mix(glm::vec<L, T, P>(-1), glm::vec<L, T, P>(1), FirstQuarterPi));
glm::vec<L, T, P> const SectionAngle(RevertAngle - Angle0_PI);
glm::vec<L, T, Q> const RevertAngle(mix(glm::vec<L, T, Q>(glm::pi<T>()), glm::vec<L, T, Q>(0), FirstQuarterPi));
glm::vec<L, T, Q> const ReturnSign(mix(glm::vec<L, T, Q>(-1), glm::vec<L, T, Q>(1), FirstQuarterPi));
glm::vec<L, T, Q> const SectionAngle(RevertAngle - Angle0_PI);
return ReturnSign * taylorSeriesRefCos(SectionAngle);
}

View File

@@ -3,21 +3,21 @@
#include <glm/gtc/constants.hpp>
#include <glm/gtc/epsilon.hpp>
template <glm::length_t C, glm::length_t R, typename T, glm::qualifier P, template<glm::length_t, glm::length_t, typename, glm::qualifier> class matType>
int test_qr(matType<C, R, T, P> m)
template <glm::length_t C, glm::length_t R, typename T, glm::qualifier Q>
int test_qr(glm::mat<C, R, T, Q> m)
{
int Error = 0;
T const epsilon = static_cast<T>(1e-10);
matType<(C < R ? C : R), R, T, P> q(-999);
matType<C, (C < R ? C : R), T, P> r(-999);
glm::mat<(C < R ? C : R), R, T, Q> q(-999);
glm::mat<C, (C < R ? C : R), T, Q> r(-999);
glm::qr_decompose(m, q, r);
//Test if q*r really equals the input matrix
matType<C, R, T, P> tm = q*r;
matType<C, R, T, P> err = tm - m;
glm::mat<C, R, T, Q> tm = q*r;
glm::mat<C, R, T, Q> err = tm - m;
for (glm::length_t i = 0; i < C; i++)
for (glm::length_t j = 0; j < R; j++)
@@ -40,28 +40,28 @@ int test_qr(matType<C, R, T, P> m)
return Error;
}
template <glm::length_t C, glm::length_t R, typename T, glm::qualifier P, template<glm::length_t, glm::length_t, typename, glm::qualifier> class matType>
int test_rq(matType<C, R, T, P> m)
template <glm::length_t C, glm::length_t R, typename T, glm::qualifier Q>
int test_rq(glm::mat<C, R, T, Q> m)
{
int Error = 0;
T const epsilon = static_cast<T>(1e-10);
matType<C, (C < R ? C : R), T, P> q(-999);
matType<(C < R ? C : R), R, T, P> r(-999);
glm::mat<C, (C < R ? C : R), T, Q> q(-999);
glm::mat<(C < R ? C : R), R, T, Q> r(-999);
glm::rq_decompose(m, r, q);
//Test if q*r really equals the input matrix
matType<C, R, T, P> tm = r*q;
matType<C, R, T, P> err = tm - m;
glm::mat<C, R, T, Q> tm = r*q;
glm::mat<C, R, T, Q> err = tm - m;
for (glm::length_t i = 0; i < C; i++)
for (glm::length_t j = 0; j < R; j++)
Error += glm::abs(err[i][j]) > epsilon ? 1 : 0;
//Test if the rows of q are orthonormal
matType<(C < R ? C : R), C, T, P> tq = transpose(q);
glm::mat<(C < R ? C : R), C, T, Q> tq = transpose(q);
for (glm::length_t i = 0; i < (C < R ? C : R); i++)
{