From 100ae8efcc592ec44f0cc161e0045fb84b67c45e Mon Sep 17 00:00:00 2001 From: smatz Date: Thu, 27 Aug 2009 13:31:26 +0000 Subject: (svn r17292) -Codechange: use unified ToPercent() function to convert fract numbers to percents --- src/core/math_func.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/core') diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index 39ed16c98..b27fe9a01 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -269,6 +269,28 @@ static FORCEINLINE void Swap(T &a, T &b) b = t; } +/** + * Converts a "fract" value 0..255 to "percent" value 0..100 + * @param i value to convert, range 0..255 + * @return value in range 0..100 + */ +static FORCEINLINE uint ToPercent8(uint i) +{ + assert(i < 256); + return i * 101 >> 8; +} + +/** + * Converts a "fract" value 0..65535 to "percent" value 0..100 + * @param i value to convert, range 0..65535 + * @return value in range 0..100 + */ +static FORCEINLINE uint ToPercent16(uint i) +{ + assert(i < 65536); + return i * 101 >> 16; +} + int LeastCommonMultiple(int a, int b); int GreatestCommonDivisor(int a, int b); -- cgit v1.2.3-70-g09d2