aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/DoubleConverter.h
blob: 18cbe4e3a1dd4bf8ad1efd3e9f5ed87823485eaa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdouble-promotion"
#endif

#include <base/defines.h>
#include <double-conversion/double-conversion.h>
#include <boost/noncopyable.hpp>

#ifdef __clang__
#pragma clang diagnostic pop
#endif


namespace DB
{

template <bool emit_decimal_point> struct DoubleToStringConverterFlags
{
    static constexpr auto flags = double_conversion::DoubleToStringConverter::NO_FLAGS;
};

template <> struct DoubleToStringConverterFlags<true>
{
    static constexpr auto flags = double_conversion::DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT;
};

template <bool emit_decimal_point>
class DoubleConverter : private boost::noncopyable
{
    DoubleConverter() = default;

public:
    /// Sign (1 byte) + DigitsBeforePoint + point (1 byte) + DigitsAfterPoint + zero byte.
    /// See comment to DoubleToStringConverter::ToFixed method for explanation.
    static constexpr auto MAX_REPRESENTATION_LENGTH =
            1 + double_conversion::DoubleToStringConverter::kMaxFixedDigitsBeforePoint +
            1 + double_conversion::DoubleToStringConverter::kMaxFixedDigitsAfterPoint + 1;
    using BufferType = char[MAX_REPRESENTATION_LENGTH];

    static const double_conversion::DoubleToStringConverter & instance();
};

}