ClickHouse/dbms/Functions/isInfinite.cpp
Ivan 97f2a2213e
Move all folders inside /dbms one level up (#9974)
* Move some code outside dbms/src folder
* Fix paths
2020-04-02 02:51:21 +03:00

41 lines
1.0 KiB
C++

#include <Functions/FunctionNumericPredicate.h>
#include <Functions/FunctionFactory.h>
#include <ext/bit_cast.h>
#include <type_traits>
namespace DB
{
struct IsInfiniteImpl
{
static constexpr auto name = "isInfinite";
template <typename T>
static bool execute(const T t)
{
if constexpr (std::is_same_v<T, float>)
return (ext::bit_cast<uint32_t>(t)
& 0b01111111111111111111111111111111)
== 0b01111111100000000000000000000000;
else if constexpr (std::is_same_v<T, double>)
return (ext::bit_cast<uint64_t>(t)
& 0b0111111111111111111111111111111111111111111111111111111111111111)
== 0b0111111111110000000000000000000000000000000000000000000000000000;
else
{
(void)t;
return false;
}
}
};
using FunctionIsInfinite = FunctionNumericPredicate<IsInfiniteImpl>;
void registerFunctionIsInfinite(FunctionFactory & factory)
{
factory.registerFunction<FunctionIsInfinite>();
}
}