From 9d75600ac0137907d5c5ec4f0ff475e2efa2f596 Mon Sep 17 00:00:00 2001 From: btzy Date: Sat, 12 Jan 2019 16:28:43 +0800 Subject: Fix: Round up deltas for smooth scrolling, so target will be reached --- src/core/math_func.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/core/math_func.hpp') diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index df9142462..4a19033f4 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -346,6 +346,23 @@ static inline int RoundDivSU(int a, uint b) } } +/** + * Computes (a / b) rounded away from zero. + * @param a Numerator + * @param b Denominator + * @return Quotient, rounded away from zero + */ +static inline int DivAwayFromZero(int a, uint b) +{ + const int _b = static_cast(b); + if (a > 0) { + return (a + _b - 1) / _b; + } else { + /* Note: Behaviour of negative numerator division is truncation toward zero. */ + return (a - _b + 1) / _b; + } +} + uint32 IntSqrt(uint32 num); #endif /* MATH_FUNC_HPP */ -- cgit v1.2.3-54-g00ecf