Skip to content

Commit

Permalink
Change numlen function to handle negative numbers properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedws committed Nov 17, 2018
1 parent 5873fee commit e16346d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion common/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ int numlen(int n) {
if (n == 0) {
return 1;
}
return log10(abs(n)) + 1;
// Account for the '-' in negative numbers.
return log10(abs(n)) + (n > 0 ? 1 : 2);
}

static struct modifier_key {
Expand Down

0 comments on commit e16346d

Please sign in to comment.