zfs_source_code.c
/*
 * Convert a number to an appropriately human-readable output.
 */
Convert a number to an appropriately human-readable output.
Convert a number to an appropriately human - readable output .
void
zfs_nicenum(uint64_t num, char *buf, size_t buflen)
{
	uint64_t n = num;
	int index = 0;
	char u;
	while (n >= 1024) {
		n /= 1024;
		index++;
	}
	u = " KMGTPE"[index];
	if (index == 0) {
		(void) snprintf(buf, buflen, "%llu", n);
	} else if ((num & ((1ULL << 10 * index) - 1)) == 0) {
		(void) snprintf(buf, buflen, "%llu%c", n, u);
	} else {
		int i;
		for (i = 2; i >= 0; i--) {
			if (snprintf(buf, buflen, "%.*f%c", i,
			    (double)num / (1ULL << 10 * index), u) <= 5)
				break;
		}
	}
}
void zfs_nicenum ( uint64_t num , char * buf , size_t buflen ) { uint64_t n = num ; int index = 0 ; char u ; while ( n >= 1024 ) { n /= 1024 ; index ++ ; } u = " " [ index ] ; if ( index == 0 ) { ( void ) snprintf ( buf , buflen , " " , n ) ; } else if ( ( num & ( ( 1ULL << 10 * index ) - 1 ) ) == 0 ) { ( void ) snprintf ( buf , buflen , " " , n , u ) ; } else { int i ; for ( i = 2 ; i >= 0 ; i -- ) { if ( snprintf ( buf , buflen , " " , i , ( double ) num / ( 1ULL << 10 * index ) , u ) <= 5 ) break ; } } }
Convert a number to an appropriately human-readable output.
Convert a number to an appropriately human - readable output .
/*
		 * If this is an even multiple of the base, always display
		 * without any decimal precision.
		 */ /*
		 * We want to choose a precision that reflects the best choice
		 * for fitting in 5 characters.  This can get rather tricky when
		 * we have numbers that are very close to an order of magnitude.
		 * For example, when displaying 10239 (which is really 9.999K),
		 * we want only a single place of precision for 10.0K.  We could
		 * develop some complex heuristics for this, but it's much
		 * easier just to try each combination in turn.
		 */