ClickHouse/src/Functions/intDivOrZero.cpp

37 lines
966 B
C++
Raw Normal View History

#include <Functions/FunctionFactory.h>
#include <Functions/FunctionBinaryArithmetic.h>
2019-07-31 01:05:33 +00:00
namespace DB
{
template <typename A, typename B>
struct DivideIntegralOrZeroImpl
{
using ResultType = typename NumberTraits::ResultOfIntegerDivision<A, B>::Type;
static const constexpr bool allow_fixed_string = false;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
{
2019-07-31 01:05:33 +00:00
if (unlikely(divisionLeadsToFPE(a, b)))
return 0;
2019-07-31 18:04:24 +00:00
return DivideIntegralImpl<A, B>::template apply<Result>(a, b);
}
#if USE_EMBEDDED_COMPILER
static constexpr bool compilable = false; /// TODO implement the checks
#endif
};
struct NameIntDivOrZero { static constexpr auto name = "intDivOrZero"; };
using FunctionIntDivOrZero = FunctionBinaryArithmetic<DivideIntegralOrZeroImpl, NameIntDivOrZero>;
void registerFunctionIntDivOrZero(FunctionFactory & factory)
{
factory.registerFunction<FunctionIntDivOrZero>();
}
}