diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-09-21 22:22:35 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-09-21 23:18:40 +0300 |
commit | c11f17020732d96e6830deadb8272f66c9af623b (patch) | |
tree | 23694297ff60d27ee6d60aa041141a6264a244db /src/common | |
parent | c3f46b2c8f3d05a44c2d7388756666e98b9323bb (diff) | |
download | hercules-c11f17020732d96e6830deadb8272f66c9af623b.tar.gz hercules-c11f17020732d96e6830deadb8272f66c9af623b.tar.bz2 hercules-c11f17020732d96e6830deadb8272f66c9af623b.tar.xz hercules-c11f17020732d96e6830deadb8272f66c9af623b.zip |
Convert some functions from int32 types to int64.
This mainly need for base and job exp, because now they using int64 type.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/utils.c | 22 | ||||
-rw-r--r-- | src/common/utils.h | 1 |
2 files changed, 23 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. * diff --git a/src/common/utils.h b/src/common/utils.h index 9d3c323ef..e77c63cf2 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -44,6 +44,7 @@ bool exists(const char* filename); /// calculates the value of A / B, in percent (rounded down) unsigned int get_percentage(const unsigned int A, const unsigned int B); +uint64 get_percentage64(const uint64 A, const uint64 B); int64 apply_percentrate64(int64 value, int rate, int maxrate); int apply_percentrate(int value, int rate, int maxrate); |