Skip to content

Commit

Permalink
Merge branch '1.1.x' into 1.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Oct 21, 2019
2 parents c26a9b4 + e0f011e commit b4e97e0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ String value(double value) {
// see https://stackoverflow.com/a/3758880/510017
String humanReadableByteCount(double bytes) {
int unit = 1024;
if (bytes < unit) return decimalOrNan(bytes) + " B";
if (bytes < unit || Double.isNaN(bytes)) return decimalOrNan(bytes) + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = "KMGTPE".charAt(exp - 1) + "i";
return decimalOrNan(bytes / Math.pow(unit, exp)) + " " + pre + "B";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void humanReadableByteCount() {
.baseUnit(BaseUnits.BYTES)
.register(registry));

assertThat(printer.humanReadableBaseUnit(Double.NaN)).isEqualTo("NaN B");
assertThat(printer.humanReadableBaseUnit(1.0)).isEqualTo("1 B");
assertThat(printer.humanReadableBaseUnit(1024)).isEqualTo("1 KiB");
assertThat(printer.humanReadableBaseUnit(1024 * 1024 * 2.5678976654)).isEqualTo("2.567898 MiB");
Expand Down

0 comments on commit b4e97e0

Please sign in to comment.