https://github.com/torvalds/linux
Raw File
Tip revision: 0dd3ee31125508cd67f7e7172247f05b7fd1753a authored by Linus Torvalds on 07 January 2024, 20:18:38 UTC
Linux 6.7
Tip revision: 0dd3ee3
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