Fix binary pow formatting for values between 1000 and 1024
parent
d906080f26
commit
e14005a6aa
|
@ -56,7 +56,9 @@ struct formatter<pow_format> {
|
||||||
fraction /= base;
|
fraction /= base;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto max_width = 4 // coeff in {:.3g} format
|
auto number_width = 5 // coeff in {:.1f} format
|
||||||
|
+ s.binary_; // potential 4th digit before the decimal point
|
||||||
|
auto max_width = number_width
|
||||||
+ 1 // prefix from units array
|
+ 1 // prefix from units array
|
||||||
+ s.binary_ // for the 'i' in GiB.
|
+ s.binary_ // for the 'i' in GiB.
|
||||||
+ s.unit_.length();
|
+ s.unit_.length();
|
||||||
|
@ -69,15 +71,16 @@ struct formatter<pow_format> {
|
||||||
case '<':
|
case '<':
|
||||||
return format_to(ctx.out(), "{:<{}}", fmt::format("{}", s), max_width);
|
return format_to(ctx.out(), "{:<{}}", fmt::format("{}", s), max_width);
|
||||||
case '=':
|
case '=':
|
||||||
format = "{coefficient:<4.3g}{padding}{prefix}{unit}";
|
format = "{coefficient:<{number_width}.1f}{padding}{prefix}{unit}";
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
format = "{coefficient:.3g}{prefix}{unit}";
|
format = "{coefficient:.1f}{prefix}{unit}";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return format_to(
|
return format_to(
|
||||||
ctx.out(), format, fmt::arg("coefficient", fraction),
|
ctx.out(), format, fmt::arg("coefficient", fraction),
|
||||||
|
fmt::arg("number_width", number_width),
|
||||||
fmt::arg("prefix", std::string() + units[pow] + ((s.binary_ && pow) ? "i" : "")),
|
fmt::arg("prefix", std::string() + units[pow] + ((s.binary_ && pow) ? "i" : "")),
|
||||||
fmt::arg("unit", s.unit_),
|
fmt::arg("unit", s.unit_),
|
||||||
fmt::arg("padding", pow ? ""
|
fmt::arg("padding", pow ? ""
|
||||||
|
|
Loading…
Reference in New Issue