mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Merge branch 'fix-bad-numbers-pretty-printing' into dont-cut-single-value
This commit is contained in:
commit
fa3c9dc664
@ -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<false>::BufferType buffer;
|
||||
double_conversion::StringBuilder builder{buffer, sizeof(buffer)};
|
||||
|
||||
const auto result = DB::DoubleConverter<false>::instance().ToFixed(size, precision, &builder);
|
||||
const auto & converter = DB::DoubleConverter<false>::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);
|
||||
}
|
||||
|
||||
|
30
tests/queries/0_stateless/03019_numbers_pretty.reference
Normal file
30
tests/queries/0_stateless/03019_numbers_pretty.reference
Normal file
@ -0,0 +1,30 @@
|
||||
┏━━━━━━━━━━━━━┓
|
||||
┃ 1230000000. ┃
|
||||
┡━━━━━━━━━━━━━┩
|
||||
│ 1230000000 │ -- 1.23 billion
|
||||
└─────────────┘
|
||||
┏━━━━━━━━━━━━━━┓
|
||||
┃ -1230000000. ┃
|
||||
┡━━━━━━━━━━━━━━┩
|
||||
│ -1230000000 │ -- -1.23 billion
|
||||
└──────────────┘
|
||||
┏━━━━━┓
|
||||
┃ inf ┃
|
||||
┡━━━━━┩
|
||||
│ inf │
|
||||
└─────┘
|
||||
┏━━━━━━┓
|
||||
┃ -inf ┃
|
||||
┡━━━━━━┩
|
||||
│ -inf │
|
||||
└──────┘
|
||||
┏━━━━━┓
|
||||
┃ nan ┃
|
||||
┡━━━━━┩
|
||||
│ nan │
|
||||
└─────┘
|
||||
┏━━━━━━━┓
|
||||
┃ 1e111 ┃
|
||||
┡━━━━━━━┩
|
||||
│ 1e111 │ -- 1000000000000000206105119874289560746212057939968.00 vigintillion
|
||||
└───────┘
|
7
tests/queries/0_stateless/03019_numbers_pretty.sql
Normal file
7
tests/queries/0_stateless/03019_numbers_pretty.sql
Normal file
@ -0,0 +1,7 @@
|
||||
SET output_format_pretty_row_numbers = 0;
|
||||
SELECT 1.23e9 FORMAT Pretty;
|
||||
SELECT -1.23e9 FORMAT Pretty;
|
||||
SELECT inf FORMAT Pretty;
|
||||
SELECT -inf FORMAT Pretty;
|
||||
SELECT nan FORMAT Pretty;
|
||||
SELECT 1e111 FORMAT Pretty;
|
Loading…
Reference in New Issue
Block a user