summaryrefslogtreecommitdiff
path: root/src/common/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/utils.c')
-rw-r--r--src/common/utils.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/utils.c b/src/common/utils.c
index 354bd3814..a9ce1389f 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -221,3 +221,19 @@ uint32 MakeDWord(uint16 word0, uint16 word1)
( (uint32)(word0 ) )|
( (uint32)(word1 << 0x10) );
}
+
+
+/// calculates the value of A / B, in percent (rounded down)
+unsigned int percent(const unsigned int A, const unsigned int B)
+{
+ if( B == 0 )
+ {
+ ShowError("percent(): divison by zero!\n");
+ return -1;
+ }
+
+ if( A < UINT_MAX/100 )
+ return 100*A/B;
+ else
+ return A/(B/100);
+} \ No newline at end of file