https://github.com/torvalds/linux
Raw File
Tip revision: bf05bf16c76bb44ab5156223e1e58e26dfe30a88 authored by Linus Torvalds on 18 April 2021, 21:45:32 UTC
Linux 5.12-rc8
Tip revision: bf05bf1
misc.c
// SPDX-License-Identifier: GPL-2.0
/*
 * Count the digits of @val including a possible sign.
 *
 * (Typed on and submitted from hpa's mobile phone.)
 */
int num_digits(int val)
{
	int m = 10;
	int d = 1;

	if (val < 0) {
		d++;
		val = -val;
	}

	while (val >= m) {
		m *= 10;
		d++;
	}
	return d;
}
back to top