ClickHouse/src/Functions/isInfinite.cpp

44 lines
1.0 KiB
C++
Raw Normal View History

#include <Functions/FunctionNumericPredicate.h>
#include <Functions/FunctionFactory.h>
2021-06-15 19:55:21 +00:00
#include <common/bit_cast.h>
#include <type_traits>
namespace DB
{
2020-09-07 18:00:37 +00:00
namespace
{
struct IsInfiniteImpl
{
static constexpr auto name = "isInfinite";
template <typename T>
static bool execute(const T t)
{
if constexpr (std::is_same_v<T, float>)
2021-06-15 19:55:21 +00:00
return (bit_cast<uint32_t>(t)
& 0b01111111111111111111111111111111)
== 0b01111111100000000000000000000000;
else if constexpr (std::is_same_v<T, double>)
2021-06-15 19:55:21 +00:00
return (bit_cast<uint64_t>(t)
& 0b0111111111111111111111111111111111111111111111111111111111111111)
== 0b0111111111110000000000000000000000000000000000000000000000000000;
else
{
(void)t;
return false;
}
}
};
using FunctionIsInfinite = FunctionNumericPredicate<IsInfiniteImpl>;
2020-09-07 18:00:37 +00:00
}
void registerFunctionIsInfinite(FunctionFactory & factory)
{
factory.registerFunction<FunctionIsInfinite>();
}
}