Add templated versions of CeilDiv and Ceil maths functions

This commit is contained in:
Jonathan G Rennison
2017-10-05 18:09:46 +01:00
parent 124d9a753e
commit 6f5dc695fa

View File

@@ -318,6 +318,18 @@ static inline uint CeilDiv(uint a, uint b)
return (a + b - 1) / b;
}
/**
* Computes ceil(a / b) for non-negative a and b (templated).
* @param a Numerator
* @param b Denominator
* @return Quotient, rounded up
*/
template <typename T>
static inline T CeilDivT(T a, T b)
{
return (a + b - 1) / b;
}
/**
* Computes ceil(a / b) * b for non-negative a and b.
* @param a Numerator
@@ -329,6 +341,18 @@ static inline uint Ceil(uint a, uint b)
return CeilDiv(a, b) * b;
}
/**
* Computes ceil(a / b) * b for non-negative a and b (templated).
* @param a Numerator
* @param b Denominator
* @return a rounded up to the nearest multiple of b.
*/
template <typename T>
static inline T CeilT(T a, T b)
{
return CeilDivT<T>(a, b) * b;
}
/**
* Computes round(a / b) for signed a and unsigned b.
* @param a Numerator