diff options
author | smatz <smatz@openttd.org> | 2009-08-27 13:31:26 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-08-27 13:31:26 +0000 |
commit | 100ae8efcc592ec44f0cc161e0045fb84b67c45e (patch) | |
tree | 79e23872457025fcbbc5f0a92e071c53d687ec7b /src/core | |
parent | 984efae368da7a7a7e5090820ef31c9c3a678670 (diff) | |
download | openttd-100ae8efcc592ec44f0cc161e0045fb84b67c45e.tar.xz |
(svn r17292) -Codechange: use unified ToPercent() function to convert fract numbers to percents
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/math_func.hpp | 22 |
1 files changed, 22 insertions, 0 deletions
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); |