df
всегда округляет читабельный вывод ( -h
и -H
).
Исходя из исходного кода в пакете coreutils, lib/human.h
перечисления опций для human_readable
функции, обеспечивающей округление, преобразование единиц и т. Д .:
/* Options for human_readable. */ enum { /* Unless otherwise specified these options may be ORed together. */ /* The following three options are mutually exclusive. */ /* Round to plus infinity (default). */ human_ceiling = 0, /* Round to nearest, ties to even. */ human_round_to_nearest = 1, /* Round to minus infinity. */ human_floor = 2, ...
Обратите внимание на комментарий: Round to plus infinity (default).
Фактическое округление, скорее всего, происходит в следующей функции human.c
, которая добавляет true
(то есть 1
), если никакая другая опция округления, показанная выше, не установлена (это не -h
только устанавливает) human_autoscale | human_SI | human_base_1024
, что приводит к автоматическому масштабированию с использованием 1024 в качестве приращения единицы и печати суффикса стиля SI, т.е. G
) и значение не является целым числом:
static long double adjust_value (int inexact_style, long double value) { /* Do not use the floorl or ceill functions, as that would mean checking for their presence and possibly linking with the standard math library, which is a porting pain. So leave the value alone if it is too large to easily round. */ if (inexact_style != human_round_to_nearest && value < UINTMAX_MAX) { uintmax_t u = value; value = u + (inexact_style == human_ceiling && u != value); } return value; }