2014-12-09 11:31:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-11-16 03:10:37 +00:00
|
|
|
#include <double-conversion/double-conversion.h>
|
2014-12-09 11:31:16 +00:00
|
|
|
|
2015-11-30 15:15:45 +00:00
|
|
|
|
2014-12-09 11:31:16 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
template <bool emit_decimal_point> struct DoubleToStringConverterFlags
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto flags = double_conversion::DoubleToStringConverter::NO_FLAGS;
|
2014-12-09 11:31:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct DoubleToStringConverterFlags<true>
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static constexpr auto flags = double_conversion::DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT;
|
2014-12-09 11:31:16 +00:00
|
|
|
};
|
|
|
|
|
2015-11-30 15:15:45 +00:00
|
|
|
template <bool emit_decimal_point>
|
|
|
|
class DoubleConverter
|
2014-12-09 11:31:16 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
DoubleConverter(const DoubleConverter &) = delete;
|
|
|
|
DoubleConverter & operator=(const DoubleConverter &) = delete;
|
2014-12-09 11:31:16 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DoubleConverter() = default;
|
2015-11-30 15:15:45 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
/** @todo Add commentary on how this constant is deduced.
|
|
|
|
* e.g. it's minus sign, integral zero, decimal point, up to 5 leading zeros and kBase10MaximalLength digits. */
|
|
|
|
static constexpr auto MAX_REPRESENTATION_LENGTH = 26;
|
|
|
|
using BufferType = char[MAX_REPRESENTATION_LENGTH];
|
|
|
|
|
|
|
|
static const auto & instance()
|
|
|
|
{
|
|
|
|
static const double_conversion::DoubleToStringConverter instance{
|
|
|
|
DoubleToStringConverterFlags<emit_decimal_point>::flags, "inf", "nan", 'e', -6, 21, 6, 1
|
|
|
|
};
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
2015-11-30 15:15:45 +00:00
|
|
|
};
|
2014-12-09 11:31:16 +00:00
|
|
|
|
|
|
|
}
|