Added 'fmod' overload to GTX_common with tests, Removed integer specification for 'mod' in GTC_integer #308
This commit is contained in:
@@ -61,14 +61,5 @@ namespace detail
|
||||
}
|
||||
};
|
||||
# endif//GLM_HAS_BITSCAN_WINDOWS
|
||||
|
||||
template <typename T, precision P, template <class, precision> class vecType, typename genType>
|
||||
struct compute_mod<T, P, vecType, genType, false>
|
||||
{
|
||||
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & a, genType const & b)
|
||||
{
|
||||
return a % b;
|
||||
}
|
||||
};
|
||||
}//namespace detail
|
||||
}//namespace glm
|
||||
|
||||
@@ -68,6 +68,14 @@ namespace glm
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL typename genType::bool_type isdenormal(genType const & x);
|
||||
|
||||
/// Similiar to 'mod' but with a different rounding and integer support.
|
||||
/// Returns 'x - y * trunc(x/y)' instead of 'x - y * floor(x/y)'
|
||||
///
|
||||
/// @see <a href="http://stackoverflow.com/questions/7610631/glsl-mod-vs-hlsl-fmod">GLSL mod vs HLSL fmod</a>
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/mod.xml">GLSL mod man page</a>
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> fmod(vecType<T, P> const & v);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
||||
|
||||
@@ -32,8 +32,28 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace glm
|
||||
namespace glm{
|
||||
namespace detail
|
||||
{
|
||||
template <typename T, precision P, template <class, precision> class vecType, bool isFloat = true>
|
||||
struct compute_fmod
|
||||
{
|
||||
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & a, vecType<T, P> const & b)
|
||||
{
|
||||
return detail::functor2<T, P, vecType>::call(std::fmod, a, b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, precision P, template <class, precision> class vecType>
|
||||
struct compute_fmod<T, P, vecType, false>
|
||||
{
|
||||
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & a, vecType<T, P> const & b)
|
||||
{
|
||||
return a % b;
|
||||
}
|
||||
};
|
||||
}//namespace detail
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER bool isdenormal(T const & x)
|
||||
{
|
||||
@@ -99,4 +119,23 @@ namespace glm
|
||||
isdenormal(x.z),
|
||||
isdenormal(x.w));
|
||||
}
|
||||
|
||||
// fmod
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fmod(genType x, genType y)
|
||||
{
|
||||
return fmod(tvec1<genType>(x), y).x;
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fmod(vecType<T, P> const & x, T y)
|
||||
{
|
||||
return detail::compute_fmod<T, P, vecType, std::numeric_limits<T>::is_iec559>::call(x, vecType<T, P>(y));
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fmod(vecType<T, P> const & x, vecType<T, P> const & y)
|
||||
{
|
||||
return detail::compute_fmod<T, P, vecType, std::numeric_limits<T>::is_iec559>::call(x, y);
|
||||
}
|
||||
}//namespace glm
|
||||
|
||||
Reference in New Issue
Block a user