1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 24651b943SAnuradha Weeraman #include <asm/misc.h> 34651b943SAnuradha Weeraman 4a17bce4dSBorislav Petkov /* 5a17bce4dSBorislav Petkov * Count the digits of @val including a possible sign. 6a17bce4dSBorislav Petkov * 7a17bce4dSBorislav Petkov * (Typed on and submitted from hpa's mobile phone.) 8a17bce4dSBorislav Petkov */ num_digits(int val)9646e29a1SBorislav Petkovint num_digits(int val) 10646e29a1SBorislav Petkov { 11*2de76cf0SColin Ian King long long m = 10; 12a17bce4dSBorislav Petkov int d = 1; 13646e29a1SBorislav Petkov 14a17bce4dSBorislav Petkov if (val < 0) { 15a17bce4dSBorislav Petkov d++; 16a17bce4dSBorislav Petkov val = -val; 17646e29a1SBorislav Petkov } 18646e29a1SBorislav Petkov 19a17bce4dSBorislav Petkov while (val >= m) { 20a17bce4dSBorislav Petkov m *= 10; 21a17bce4dSBorislav Petkov d++; 22a17bce4dSBorislav Petkov } 23a17bce4dSBorislav Petkov return d; 24646e29a1SBorislav Petkov } 25