1/// @ref gtc_integer
2/// @file glm/gtc/integer.inl
3
4namespace glm{
5namespace detail
6{
7	template <typename T, precision P, template <typename, precision> class vecType, bool Aligned>
8	struct compute_log2<T, P, vecType, false, Aligned>
9	{
10		GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & vec)
11		{
12			//Equivalent to return findMSB(vec); but save one function call in ASM with VC
13			//return findMSB(vec);
14			return vecType<T, P>(detail::compute_findMSB_vec<T, P, vecType, sizeof(T) * 8>::call(vec));
15		}
16	};
17
18#	if GLM_HAS_BITSCAN_WINDOWS
19		template <precision P, bool Aligned>
20		struct compute_log2<int, P, tvec4, false, Aligned>
21		{
22			GLM_FUNC_QUALIFIER static tvec4<int, P> call(tvec4<int, P> const & vec)
23			{
24				tvec4<int, P> Result(glm::uninitialize);
25
26				_BitScanReverse(reinterpret_cast<unsigned long*>(&Result.x), vec.x);
27				_BitScanReverse(reinterpret_cast<unsigned long*>(&Result.y), vec.y);
28				_BitScanReverse(reinterpret_cast<unsigned long*>(&Result.z), vec.z);
29				_BitScanReverse(reinterpret_cast<unsigned long*>(&Result.w), vec.w);
30
31				return Result;
32			}
33		};
34#	endif//GLM_HAS_BITSCAN_WINDOWS
35}//namespace detail
36	template <typename genType>
37	GLM_FUNC_QUALIFIER int iround(genType x)
38	{
39		GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'iround' only accept floating-point inputs");
40		assert(static_cast<genType>(0.0) <= x);
41
42		return static_cast<int>(x + static_cast<genType>(0.5));
43	}
44
45	template <typename T, precision P, template <typename, precision> class vecType>
46	GLM_FUNC_QUALIFIER vecType<int, P> iround(vecType<T, P> const& x)
47	{
48		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'iround' only accept floating-point inputs");
49		assert(all(lessThanEqual(vecType<T, P>(0), x)));
50
51		return vecType<int, P>(x + static_cast<T>(0.5));
52	}
53
54	template <typename genType>
55	GLM_FUNC_QUALIFIER uint uround(genType x)
56	{
57		GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'uround' only accept floating-point inputs");
58		assert(static_cast<genType>(0.0) <= x);
59
60		return static_cast<uint>(x + static_cast<genType>(0.5));
61	}
62
63	template <typename T, precision P, template <typename, precision> class vecType>
64	GLM_FUNC_QUALIFIER vecType<uint, P> uround(vecType<T, P> const& x)
65	{
66		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'uround' only accept floating-point inputs");
67		assert(all(lessThanEqual(vecType<T, P>(0), x)));
68
69		return vecType<uint, P>(x + static_cast<T>(0.5));
70	}
71}//namespace glm
72