1/*
2 * Count the digits of @val including a possible sign.
3 *
4 * (Typed on and submitted from hpa's mobile phone.)
5 */6intnum_digits(intval)
7{
8int m = 10;
9int d = 1;
1011if (val < 0) {
12 d++;
13val = -val;
14 }
1516while (val >= m) {
17 m *= 10;
18 d++;
19 }
20return d;
21}
22