diff options
Diffstat (limited to 'arch/x86/lib/misc.c')
-rw-r--r-- | arch/x86/lib/misc.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/arch/x86/lib/misc.c b/arch/x86/lib/misc.c index bc35cde9769f..76b373af03f0 100644 --- a/arch/x86/lib/misc.c +++ b/arch/x86/lib/misc.c | |||
@@ -1,11 +1,21 @@ | |||
1 | /* | ||
2 | * Count the digits of @val including a possible sign. | ||
3 | * | ||
4 | * (Typed on and submitted from hpa's mobile phone.) | ||
5 | */ | ||
1 | int num_digits(int val) | 6 | int num_digits(int val) |
2 | { | 7 | { |
3 | int digits = 0; | 8 | int m = 10; |
9 | int d = 1; | ||
4 | 10 | ||
5 | while (val) { | 11 | if (val < 0) { |
6 | val /= 10; | 12 | d++; |
7 | digits++; | 13 | val = -val; |
8 | } | 14 | } |
9 | 15 | ||
10 | return digits; | 16 | while (val >= m) { |
17 | m *= 10; | ||
18 | d++; | ||
19 | } | ||
20 | return d; | ||
11 | } | 21 | } |