diff --git a/src/Common/formatReadable.cpp b/src/Common/formatReadable.cpp index c72733323d3..7e126a72c33 100644 --- a/src/Common/formatReadable.cpp +++ b/src/Common/formatReadable.cpp @@ -13,8 +13,6 @@ namespace DB } } -// I wanted to make this ALWAYS_INLINE to prevent flappy performance tests, -// but GCC complains it may not be inlined. static void formatReadable(double size, DB::WriteBuffer & out, int precision, const char ** units, size_t units_size, double delimiter) { @@ -25,7 +23,12 @@ static void formatReadable(double size, DB::WriteBuffer & out, DB::DoubleConverter::BufferType buffer; double_conversion::StringBuilder builder{buffer, sizeof(buffer)}; - const auto result = DB::DoubleConverter::instance().ToFixed(size, precision, &builder); + const auto & converter = DB::DoubleConverter::instance(); + + auto result = converter.ToFixed(size, precision, &builder); + + if (!result) + result = converter.ToShortest(size, &builder); if (!result) throw DB::Exception(DB::ErrorCodes::CANNOT_PRINT_FLOAT_OR_DOUBLE_NUMBER, "Cannot print float or double number"); @@ -65,7 +68,11 @@ std::string formatReadableSizeWithDecimalSuffix(double value, int precision) void formatReadableQuantity(double value, DB::WriteBuffer & out, int precision) { - const char * units[] = {"", " thousand", " million", " billion", " trillion", " quadrillion"}; + const char * units[] = {"", " thousand", " million", " billion", " trillion", " quadrillion", + " quintillion", " sextillion", " septillion", " octillion", " nonillion", " decillion", + " undecillion", " duodecillion", " tredecillion", " quattuordecillion", " quindecillion", + " sexdecillion", " septendecillion", " octodecillion", " novemdecillion", " vigintillion"}; + formatReadable(value, out, precision, units, sizeof(units) / sizeof(units[0]), 1000); } diff --git a/tests/queries/0_stateless/03019_numbers_pretty.reference b/tests/queries/0_stateless/03019_numbers_pretty.reference index dd441dcd48f..5b25d3dd092 100644 --- a/tests/queries/0_stateless/03019_numbers_pretty.reference +++ b/tests/queries/0_stateless/03019_numbers_pretty.reference @@ -23,3 +23,8 @@ ┡━━━━━┩ │ nan │ └─────┘ +┏━━━━━━━┓ +┃ 1e111 ┃ +┡━━━━━━━┩ +│ 1e111 │ -- 1000000000000000206105119874289560746212057939968.00 vigintillion +└───────┘ diff --git a/tests/queries/0_stateless/03019_numbers_pretty.sql b/tests/queries/0_stateless/03019_numbers_pretty.sql index e6d47abcd17..91efbe61d43 100644 --- a/tests/queries/0_stateless/03019_numbers_pretty.sql +++ b/tests/queries/0_stateless/03019_numbers_pretty.sql @@ -4,3 +4,4 @@ SELECT -1.23e9 FORMAT Pretty; SELECT inf FORMAT Pretty; SELECT -inf FORMAT Pretty; SELECT nan FORMAT Pretty; +SELECT 1e111 FORMAT Pretty;