ModuloLegacy function

This commit is contained in:
kssenii 2021-05-15 18:45:19 +00:00
parent 99e2f83c69
commit d303975a1c
6 changed files with 33 additions and 0 deletions

View File

@ -116,6 +116,12 @@ template <typename A, typename B> struct ResultOfModulo
using Type = std::conditional_t<std::is_floating_point_v<A> || std::is_floating_point_v<B>, Float64, Type0>;
};
template <typename A, typename B> struct ResultOfModuloLegacy
{
using Type0 = typename Construct<is_signed_v<A> || is_signed_v<B>, false, sizeof(B)>::Type;
using Type = std::conditional_t<std::is_floating_point_v<A> || std::is_floating_point_v<B>, Float64, Type0>;
};
template <typename A> struct ResultOfNegate
{
using Type = typename Construct<

View File

@ -172,4 +172,10 @@ struct ModuloImpl
#endif
};
template <typename A, typename B>
struct ModuloLegacyImpl : ModuloImpl<A, B>
{
using ResultType = typename NumberTraits::ResultOfModuloLegacy<A, B>::Type;
};
}

View File

@ -96,6 +96,11 @@ struct ModuloByConstantImpl
}
};
template <typename A, typename B>
struct ModuloLegacyByConstantImpl : ModuloByConstantImpl<A, B>
{
using Op = ModuloLegacyImpl<A, B>;
};
}
/** Specializations are specified for dividing numbers of the type UInt64 and UInt32 by the numbers of the same sign.
@ -134,4 +139,12 @@ void registerFunctionModulo(FunctionFactory & factory)
factory.registerAlias("mod", "modulo", FunctionFactory::CaseInsensitive);
}
struct NameModuloLegacy { static constexpr auto name = "moduloLegacy"; };
using FunctionModuloLegacy = BinaryArithmeticOverloadResolver<ModuloLegacyImpl, NameModuloUnsigned, false>;
void registerFunctionModuloLegacy(FunctionFactory & factory)
{
factory.registerFunction<FunctionModuloLegacy>();
}
}

View File

@ -11,6 +11,7 @@ void registerFunctionIntDiv(FunctionFactory & factory);
void registerFunctionIntDivOrZero(FunctionFactory & factory);
void registerFunctionModulo(FunctionFactory & factory);
void registerFunctionModuloOrZero(FunctionFactory & factory);
void registerFunctionModuloLegacy(FunctionFactory & factory);
void registerFunctionNegate(FunctionFactory & factory);
void registerFunctionAbs(FunctionFactory & factory);
void registerFunctionBitAnd(FunctionFactory & factory);
@ -51,6 +52,7 @@ void registerFunctionsArithmetic(FunctionFactory & factory)
registerFunctionIntDivOrZero(factory);
registerFunctionModulo(factory);
registerFunctionModuloOrZero(factory);
registerFunctionModuloLegacy(factory);
registerFunctionNegate(factory);
registerFunctionAbs(factory);
registerFunctionBitAnd(factory);

View File

@ -0,0 +1,3 @@
199
99
57

View File

@ -0,0 +1,3 @@
SELECT moduloLegacy(199, 200);
SELECT moduloLegacy(299, 200);
SELECT moduloLegacy(-199, 200);