https://github.com/torvalds/linux
Raw File
Tip revision: f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6 authored by Linus Torvalds on 14 May 2023, 19:51:40 UTC
Linux 6.4-rc2
Tip revision: f1fcbaa
misc.c
// SPDX-License-Identifier: GPL-2.0
#include <asm/misc.h>

/*
 * 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