Add DivisionUtils.h

This commit is contained in:
hcz 2020-02-25 17:45:23 +08:00
parent 94b52c0858
commit 3b8093234c
5 changed files with 20 additions and 26 deletions

View File

@ -70,4 +70,22 @@ struct DivideIntegralImpl
#endif
};
template <typename A, typename B>
struct ModuloImpl
{
using ResultType = typename NumberTraits::ResultOfModulo<A, B>::Type;
static const constexpr bool allow_fixed_string = false;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
{
throwIfDivisionLeadsToFPE(typename NumberTraits::ToInteger<A>::Type(a), typename NumberTraits::ToInteger<B>::Type(b));
return typename NumberTraits::ToInteger<A>::Type(a) % typename NumberTraits::ToInteger<B>::Type(b);
}
#if USE_EMBEDDED_COMPILER
static constexpr bool compilable = false; /// don't know how to throw from LLVM IR
#endif
};
}

View File

@ -22,7 +22,7 @@
#include <Columns/ColumnAggregateFunction.h>
#include "IFunctionImpl.h"
#include "FunctionHelpers.h"
#include "intDiv.h"
#include "DivisionUtils.h"
#include "castTypeToEither.h"
#include "FunctionFactory.h"
#include <Common/typeid_cast.h>

View File

@ -1,6 +1,5 @@
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionBinaryArithmetic.h>
#include <Functions/intDiv.h>
#ifdef __SSE2__
#define LIBDIVIDE_USE_SSE2 1

View File

@ -1,8 +1,6 @@
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionBinaryArithmetic.h>
#include "intDiv.h"
namespace DB
{

View File

@ -11,28 +11,7 @@
namespace DB
{
namespace ErrorCodes
{
extern const int ILLEGAL_DIVISION;
}
template <typename A, typename B>
struct ModuloImpl
{
using ResultType = typename NumberTraits::ResultOfModulo<A, B>::Type;
static const constexpr bool allow_fixed_string = false;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
{
throwIfDivisionLeadsToFPE(typename NumberTraits::ToInteger<A>::Type(a), typename NumberTraits::ToInteger<B>::Type(b));
return typename NumberTraits::ToInteger<A>::Type(a) % typename NumberTraits::ToInteger<B>::Type(b);
}
#if USE_EMBEDDED_COMPILER
static constexpr bool compilable = false; /// don't know how to throw from LLVM IR
#endif
};
/// Optimizations for integer modulo by a constant.
template <typename A, typename B>
struct ModuloByConstantImpl