diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index 5910a401d8..013f03fbeb 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -408,6 +408,30 @@ static inline int DivAwayFromZero(int a, uint b) } } +/** + * Computes a / b rounded towards negative infinity for signed a and unsigned b. + * @param a Numerator + * @param b Denominator + * @return Quotient, rounded towards negative infinity + */ +template +static inline T DivTowardsNegativeInf(T a, T b) +{ + return (a / b) - (a % b < 0 ? 1 : 0); +} + +/** + * Computes a / b rounded towards positive infinity for signed a and unsigned b. + * @param a Numerator + * @param b Denominator + * @return Quotient, rounded towards positive infinity + */ +template +static inline T DivTowardsPositiveInf(T a, T b) +{ + return (a / b) + (a % b > 0 ? 1 : 0); +} + uint32 IntSqrt(uint32 num); #endif /* MATH_FUNC_HPP */