2018-11-26 16:20:40 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionBinaryArithmetic.h>
|
2019-07-08 22:30:30 +00:00
|
|
|
#include <Core/Defines.h>
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-08-19 11:52:17 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NOT_IMPLEMENTED;
|
|
|
|
}
|
2018-11-26 16:20:40 +00:00
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
template <typename A, typename B>
|
|
|
|
struct BitTestImpl
|
|
|
|
{
|
|
|
|
using ResultType = UInt8;
|
2020-02-14 07:11:37 +00:00
|
|
|
static const constexpr bool allow_fixed_string = false;
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
template <typename Result = ResultType>
|
2020-08-19 11:52:17 +00:00
|
|
|
NO_SANITIZE_UNDEFINED static inline Result apply(A a [[maybe_unused]], B b [[maybe_unused]])
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
2020-09-04 13:33:02 +00:00
|
|
|
if constexpr (is_big_int_v<A> || is_big_int_v<B>)
|
2020-08-19 11:52:17 +00:00
|
|
|
throw Exception("bitTest is not implemented for big integers as second argument", ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
else
|
|
|
|
return (typename NumberTraits::ToInteger<A>::Type(a) >> typename NumberTraits::ToInteger<B>::Type(b)) & 1;
|
2018-11-26 16:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
static constexpr bool compilable = false; /// TODO
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NameBitTest { static constexpr auto name = "bitTest"; };
|
2021-01-30 04:13:49 +00:00
|
|
|
using FunctionBitTest = BinaryArithmeticOverloadResolver<BitTestImpl, NameBitTest, true, false>;
|
2018-11-26 16:20:40 +00:00
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
void registerFunctionBitTest(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionBitTest>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|