aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/util.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/common/util.c b/common/util.c
index 60f2f160..bd7bed2d 100644
--- a/common/util.c
+++ b/common/util.c
@@ -12,11 +12,12 @@ int wrap(int i, int max) {
}
int numlen(int n) {
- if (n == 0) {
- return 1;
+ int j = n <= 0 ? 1 : 0;
+ while (n) {
+ j++;
+ n /= 10;
}
- // Account for the '-' in negative numbers.
- return log10(abs(n)) + (n > 0 ? 1 : 2);
+ return j;
}
uint32_t parse_color(const char *color) {