Simplify and fix report_formatting::shorten(), and add Petabyte unit (in case it's needed). Update affected test samples. Add T_DIR to util/test-bash-functions.

This commit is contained in:
Daniel Nichter
2012-05-07 12:16:24 -06:00
parent 7e8fbaf188
commit fdfd305dc5
7 changed files with 47 additions and 31 deletions

View File

@@ -714,20 +714,20 @@ shorten() {
echo "$num" | awk -v prec="$prec" -v div="$div" '
{
size = 4;
val = $1;
num = $1;
unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
unit = num >= 1125899906842624 ? "P" \
: num >= 1099511627776 ? "T" \
: num >= 1073741824 ? "G" \
: num >= 1048576 ? "M" \
: num >= 1024 ? "k" \
: "";
while ( int(val) && !(val % 1024) ) {
val /= 1024;
while ( num >= div ) {
num /= div;
}
while ( val > 1000 ) {
val /= div;
}
printf "%.*f%s", prec, val, unit;
printf "%.*f%s", prec, num, unit;
}
'
}