summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-08-27 13:31:26 +0000
committersmatz <smatz@openttd.org>2009-08-27 13:31:26 +0000
commit100ae8efcc592ec44f0cc161e0045fb84b67c45e (patch)
tree79e23872457025fcbbc5f0a92e071c53d687ec7b /src/core
parent984efae368da7a7a7e5090820ef31c9c3a678670 (diff)
downloadopenttd-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.hpp22
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);