maths: add some comments to rounding functions
This commit is contained in:
parent
0f4fece00f
commit
4826b4c466
14
maths.hpp
14
maths.hpp
@ -253,7 +253,7 @@ namespace util {
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Rounding
|
/// round T up to the nearest multiple of U
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
inline
|
inline
|
||||||
typename std::common_type<
|
typename std::common_type<
|
||||||
@ -262,14 +262,13 @@ namespace util {
|
|||||||
>::type
|
>::type
|
||||||
round_to (T value, U size)
|
round_to (T value, U size)
|
||||||
{
|
{
|
||||||
if (value % size == 0)
|
auto remainder = value % size;
|
||||||
return value;
|
return value + size - remainder;
|
||||||
|
|
||||||
return value + (size - value % size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
///----------------------------------------------------------------------------
|
||||||
|
/// round T up to the nearest power-of-2
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr
|
constexpr
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
@ -290,7 +289,8 @@ namespace util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
///----------------------------------------------------------------------------
|
||||||
|
/// round T up to the nearest multiple of U and return the quotient.
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
constexpr std::enable_if_t<
|
constexpr std::enable_if_t<
|
||||||
std::is_integral<T>::value &&
|
std::is_integral<T>::value &&
|
||||||
|
Loading…
Reference in New Issue
Block a user