mirror of
https://github.com/g-truc/glm.git
synced 2024-11-10 04:31:47 +00:00
Added uround to GTC_integer, fast round on positive values
This commit is contained in:
parent
f48fe286ad
commit
c853df1638
@ -99,6 +99,19 @@ namespace glm
|
|||||||
template <typename T, precision P, template <typename, precision> class vecType>
|
template <typename T, precision P, template <typename, precision> class vecType>
|
||||||
GLM_FUNC_DECL vecType<T, P> mod(vecType<T, P> const & x, vecType<T, P> const & y);
|
GLM_FUNC_DECL vecType<T, P> mod(vecType<T, P> const & x, vecType<T, P> const & y);
|
||||||
|
|
||||||
|
/// Returns a value equal to the nearest integer to x.
|
||||||
|
/// The fraction 0.5 will round in a direction chosen by the
|
||||||
|
/// implementation, presumably the direction that is fastest.
|
||||||
|
///
|
||||||
|
/// @param x The values of the argument must be greater or equal to zero.
|
||||||
|
/// @tparam T floating point scalar types.
|
||||||
|
/// @tparam vecType vector types.
|
||||||
|
///
|
||||||
|
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/round.xml">GLSL round man page</a>
|
||||||
|
/// @see gtc_integer
|
||||||
|
template <typename T, precision P, template <typename, precision> class vecType>
|
||||||
|
GLM_FUNC_DECL vecType<uint, P> uround(vecType<T, P> const & x);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
} //namespace glm
|
} //namespace glm
|
||||||
|
|
||||||
|
@ -62,4 +62,22 @@ namespace detail
|
|||||||
};
|
};
|
||||||
# endif//GLM_HAS_BITSCAN_WINDOWS
|
# endif//GLM_HAS_BITSCAN_WINDOWS
|
||||||
}//namespace detail
|
}//namespace detail
|
||||||
|
|
||||||
|
template <typename genType>
|
||||||
|
GLM_FUNC_QUALIFIER uint uround(genType x)
|
||||||
|
{
|
||||||
|
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'round' only accept floating-point inputs");
|
||||||
|
assert(static_cast<genType>(0.0) <= x);
|
||||||
|
|
||||||
|
return static_cast<uint>(x + static_cast<genType>(0.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, precision P, template <typename, precision> class vecType>
|
||||||
|
GLM_FUNC_QUALIFIER vecType<uint, P> uround(vecType<T, P> const& x)
|
||||||
|
{
|
||||||
|
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'uround' only accept floating-point inputs");
|
||||||
|
assert(all(lessThanEqual(vecType<T, P>(0), x)));
|
||||||
|
|
||||||
|
return vecType<uint, P>(x + static_cast<T>(0.5));
|
||||||
|
}
|
||||||
}//namespace glm
|
}//namespace glm
|
||||||
|
@ -61,6 +61,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
|
|||||||
- Added 16bit pack and unpack to GTC_packing
|
- Added 16bit pack and unpack to GTC_packing
|
||||||
- Added 8bit pack and unpack to GTC_packing
|
- Added 8bit pack and unpack to GTC_packing
|
||||||
- Added missing bvec* && and || operators
|
- Added missing bvec* && and || operators
|
||||||
|
- Added uround to GTC_integer, fast round on positive values
|
||||||
|
|
||||||
##### Improvements:
|
##### Improvements:
|
||||||
- Improved GTC_random linearRand documentation
|
- Improved GTC_random linearRand documentation
|
||||||
|
@ -210,11 +210,30 @@ namespace log2_
|
|||||||
}
|
}
|
||||||
}//namespace log2_
|
}//namespace log2_
|
||||||
|
|
||||||
|
namespace uround
|
||||||
|
{
|
||||||
|
int test()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
for(float f = 0.0f; f < 3.1f; f += 0.05f)
|
||||||
|
{
|
||||||
|
int RoundFast = glm::uround(f);
|
||||||
|
int RoundSTD = std::round(f);
|
||||||
|
Error += RoundFast == RoundSTD ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
}//namespace uround
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int Error(0);
|
int Error(0);
|
||||||
|
|
||||||
Error += ::log2_::test();
|
Error += ::log2_::test();
|
||||||
|
Error += ::uround::test();
|
||||||
|
|
||||||
# ifdef NDEBUG
|
# ifdef NDEBUG
|
||||||
std::size_t const Samples(1000);
|
std::size_t const Samples(1000);
|
||||||
|
Loading…
Reference in New Issue
Block a user