Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
4651b943 AW |
2 | #include <asm/misc.h> |
3 | ||
a17bce4d BP |
4 | /* |
5 | * Count the digits of @val including a possible sign. | |
6 | * | |
7 | * (Typed on and submitted from hpa's mobile phone.) | |
8 | */ | |
646e29a1 BP |
9 | int num_digits(int val) |
10 | { | |
a17bce4d BP |
11 | int m = 10; |
12 | int d = 1; | |
646e29a1 | 13 | |
a17bce4d BP |
14 | if (val < 0) { |
15 | d++; | |
16 | val = -val; | |
646e29a1 BP |
17 | } |
18 | ||
a17bce4d BP |
19 | while (val >= m) { |
20 | m *= 10; | |
21 | d++; | |
22 | } | |
23 | return d; | |
646e29a1 | 24 | } |