comparison lib/human.c @ 5458:81e1a3092078

Import from coreutils.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 17 Nov 2004 07:18:27 +0000
parents a535859efd14
children fd10cf72c81b
comparison
equal deleted inserted replaced
5457:05fcfdcb38a6 5458:81e1a3092078
155 output. Use powers of 1024 if (OPTS & human_base_1024), and powers 155 output. Use powers of 1024 if (OPTS & human_base_1024), and powers
156 of 1000 otherwise. For example, assuming powers of 1024, 8500 156 of 1000 otherwise. For example, assuming powers of 1024, 8500
157 would be converted to 8.3, 133456345 to 127, 56990456345 to 53, and 157 would be converted to 8.3, 133456345 to 127, 56990456345 to 53, and
158 so on. Numbers smaller than the power aren't modified. 158 so on. Numbers smaller than the power aren't modified.
159 human_autoscale is normally used together with human_SI. 159 human_autoscale is normally used together with human_SI.
160
161 If (OPTS & human_space_before_unit), use a space to separate the
162 number from any suffix that is appended as described below.
160 163
161 If (OPTS & human_SI), append an SI prefix indicating which power is 164 If (OPTS & human_SI), append an SI prefix indicating which power is
162 being used. If in addition (OPTS & human_B), append "B" (if base 165 being used. If in addition (OPTS & human_B), append "B" (if base
163 1000) or "iB" (if base 1024) to the SI prefix. When ((OPTS & 166 1000) or "iB" (if base 1024) to the SI prefix. When ((OPTS &
164 human_SI) && ! (OPTS & human_autoscale)), TO_BLOCK_SIZE must be a 167 human_SI) && ! (OPTS & human_autoscale)), TO_BLOCK_SIZE must be a
381 exponent = 0; 384 exponent = 0;
382 for (power = 1; power < to_block_size; power *= base) 385 for (power = 1; power < to_block_size; power *= base)
383 if (++exponent == exponent_max) 386 if (++exponent == exponent_max)
384 break; 387 break;
385 } 388 }
389
390 if ((exponent | (opts & human_B)) && (opts & human_space_before_unit))
391 *psuffix++ = ' ';
386 392
387 if (exponent) 393 if (exponent)
388 *psuffix++ = (! (opts & human_base_1024) && exponent == 1 394 *psuffix++ = (! (opts & human_base_1024) && exponent == 1
389 ? 'k' 395 ? 'k'
390 : power_letter[exponent]); 396 : power_letter[exponent]);