}
#endif
-const int MAX_UNIT_FORMAT_SYMBOLS = 9;
+const int MAX_UNIT_FORMAT_SYMBOLS = 6;
const string shortUnitFormatSymbols[MAX_UNIT_FORMAT_SYMBOLS] = {
" B",
" MB",
" GB",
" TB",
- " PB",
- " EB",
- " ZB",
- " YB"
+ " PB"
};
const string longUnitFormatSymbols[MAX_UNIT_FORMAT_SYMBOLS] = {
i18n_noop(" MBytes"),
i18n_noop(" GBytes"),
i18n_noop(" TBytes"),
- i18n_noop(" PBytes"),
- i18n_noop(" EBytes"),
- i18n_noop(" ZBytes"),
- i18n_noop(" YBytes")
+ i18n_noop(" PBytes")
};
{
size = size / multiple;
sizecount++;
+
+ // rollback to the previous values and stop the loop when cannot
+ // represent the number length.
+ if (sizecount >= MAX_UNIT_FORMAT_SYMBOLS)
+ {
+ size = size * multiple;
+ sizecount--;
+ break;
+ }
}
// round the input number "half up" to multiples of 10
const int64_t two_exabytes = 2000000000000000000LL;
string output = nice_unit_format(two_exabytes);
- BOOST_CHECK_EQUAL(string("2.00 EBytes"), output);
+ BOOST_CHECK_EQUAL(string("2000.00 PBytes"), output);
output = nice_unit_format(two_exabytes, UnitBase1024, ShortUnitFormat);
- BOOST_CHECK_EQUAL(string("1.7 EB"), output);
+ BOOST_CHECK_EQUAL(string("1776.4 PB"), output);
const int64_t two_and_half_exabytes = 2500000000000000000LL;
output = nice_unit_format(two_and_half_exabytes);
- BOOST_CHECK_EQUAL(string("2.50 EBytes"), output);
+ BOOST_CHECK_EQUAL(string("2500.00 PBytes"), output);
output = nice_unit_format(two_and_half_exabytes, UnitBase1024, ShortUnitFormat);
- BOOST_CHECK_EQUAL(string("2.2 EB"), output);
+ BOOST_CHECK_EQUAL(string("2220.4 PB"), output);
+}
+
+BOOST_AUTO_TEST_CASE(nice_unit_format8)
+{
+ const int64_t max_representable_64bits_number = 9223372036854775807LL;
+
+ string output = nice_unit_format(max_representable_64bits_number);
+ BOOST_CHECK_EQUAL(string("9223.40 PBytes"), output);
+
+ output = nice_unit_format(max_representable_64bits_number, UnitBase1024, ShortUnitFormat);
+ BOOST_CHECK_EQUAL(string("8192.0 PB"), output);
}