blob: a018ec4fba53ef456264b14dabfdf30575e346f5 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Borislav Petkova17bce42013-09-30 11:56:24 +02002/*
3 * Count the digits of @val including a possible sign.
4 *
5 * (Typed on and submitted from hpa's mobile phone.)
6 */
Borislav Petkov646e29a2013-09-27 16:35:54 +02007int num_digits(int val)
8{
Borislav Petkova17bce42013-09-30 11:56:24 +02009 int m = 10;
10 int d = 1;
Borislav Petkov646e29a2013-09-27 16:35:54 +020011
Borislav Petkova17bce42013-09-30 11:56:24 +020012 if (val < 0) {
13 d++;
14 val = -val;
Borislav Petkov646e29a2013-09-27 16:35:54 +020015 }
16
Borislav Petkova17bce42013-09-30 11:56:24 +020017 while (val >= m) {
18 m *= 10;
19 d++;
20 }
21 return d;
Borislav Petkov646e29a2013-09-27 16:35:54 +020022}