https://github.com/torvalds/linux
Raw File
Tip revision: 6f7da290413ba713f0cdd9ff1a2a9bb129ef4f6c authored by Linus Torvalds on 02 July 2017, 23:07:02 UTC
Linux 4.12
Tip revision: 6f7da29
misc.c
/*
 * 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