aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/mathConstants.cpp
blob: c7eb37289acfecc2c9276242533f751d6ba31185 (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
47
#include <Functions/FunctionConstantBase.h>
#include <DataTypes/DataTypesNumber.h>

namespace DB
{

namespace
{
    template <typename Impl>
    class FunctionMathConstFloat64 : public FunctionConstantBase<FunctionMathConstFloat64<Impl>, Float64, DataTypeFloat64>
    {
    public:
        static constexpr auto name = Impl::name;
        static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionMathConstFloat64>(); }
        FunctionMathConstFloat64() : FunctionConstantBase<FunctionMathConstFloat64<Impl>, Float64, DataTypeFloat64>(Impl::value) {}
    };


    struct EImpl
    {
        static constexpr char name[] = "e";
        static constexpr double value = 2.7182818284590452353602874713526624977572470;
    };

    using FunctionE = FunctionMathConstFloat64<EImpl>;


    struct PiImpl
    {
        static constexpr char name[] = "pi";
        static constexpr double value = 3.1415926535897932384626433832795028841971693;
    };

    using FunctionPi = FunctionMathConstFloat64<PiImpl>;
}

REGISTER_FUNCTION(E)
{
    factory.registerFunction<FunctionE>();
}

REGISTER_FUNCTION(Pi)
{
    factory.registerFunction<FunctionPi>({}, FunctionFactory::CaseInsensitive);
}

}