aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/tanh.cpp
blob: bdefa5263d7d896d51548a1e24d1f94531298f3f (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
#include <Functions/FunctionMathUnary.h>
#include <Functions/FunctionFactory.h>

namespace DB
{
namespace
{

struct TanhName { static constexpr auto name = "tanh"; };

#if USE_FASTOPS

    struct Impl
    {
        static constexpr auto name = TanhName::name;
        static constexpr auto rows_per_iteration = 0;
        static constexpr bool always_returns_float64 = false;

        template <typename T>
        static void execute(const T * src, size_t size, T * dst)
        {
            NFastOps::Tanh<>(src, size, dst);
        }
    };

using FunctionTanh = FunctionMathUnary<Impl>;

#else

double tanh(double x)
{
    return 2 / (1.0 + exp(-2 * x)) - 1;
}

using FunctionTanh = FunctionMathUnary<UnaryFunctionVectorized<TanhName, tanh>>;
#endif

}

REGISTER_FUNCTION(Tanh)
{
    factory.registerFunction<FunctionTanh>({}, FunctionFactory::CaseInsensitive);
}

}