summaryrefslogtreecommitdiff
path: root/src/common/utils.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2017-09-22 00:13:15 +0200
committerGitHub <noreply@github.com>2017-09-22 00:13:15 +0200
commit46f5d10a555785899c04eda74e21922e92a2fb5b (patch)
tree934ec81ed964a7409ad2ba73616210f3cdf12389 /src/common/utils.c
parent7cbd35644b73f254fc976070cd1e993aa43a7cfc (diff)
parentee666f0279bca6dab137a8a8199665b7a4e7f8d8 (diff)
downloadhercules-46f5d10a555785899c04eda74e21922e92a2fb5b.tar.gz
hercules-46f5d10a555785899c04eda74e21922e92a2fb5b.tar.bz2
hercules-46f5d10a555785899c04eda74e21922e92a2fb5b.tar.xz
hercules-46f5d10a555785899c04eda74e21922e92a2fb5b.zip
Merge pull request #1844 from 4144/newpackets
Add packets for almost all 2014-2017 clients
Diffstat (limited to 'src/common/utils.c')
-rw-r--r--src/common/utils.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/utils.c b/src/common/utils.c
index bcfc153e3..0d76a885e 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -359,6 +359,28 @@ unsigned int get_percentage(const unsigned int A, const unsigned int B)
return (unsigned int)floor(result);
}
+/// calculates the value of A / B, in percent (rounded down)
+uint64 get_percentage64(const uint64 A, const uint64 B)
+{
+ double result;
+
+ if( B == 0 )
+ {
+ ShowError("get_percentage(): division by zero! (A=%"PRIu64",B=%"PRIu64")\n", A, B);
+ return ~0U;
+ }
+
+ result = 100 * ((double)A / (double)B);
+
+ if( result > UINT_MAX )
+ {
+ ShowError("get_percentage(): result percentage too high! (A=%"PRIu64",B=%"PRIu64",result=%g)\n", A, B, result);
+ return UINT_MAX;
+ }
+
+ return (uint64)floor(result);
+}
+
/**
* Applies a percentual rate modifier.
*