github-actions[bot] commented on code in PR #25386:
URL: https://github.com/apache/doris/pull/25386#discussion_r1364288519


##########
be/src/vec/core/accurate_comparison.h:
##########
@@ -464,6 +467,114 @@ template <typename A, typename B>
 inline bool_if_safe_conversion<A, B> greaterOrEqualsOp(A a, B b) {
     return a >= b;
 }
+*/
+
+template <typename A, typename B>
+bool lessOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a < b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a < b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a < b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a < 0 || static_cast<make_unsigned_t<A>>(a) < b;
+
+        if constexpr (!is_signed_v<A> && is_signed_v<B>)
+            return b >= 0 && a < static_cast<make_unsigned_t<B>>(b);
+    }
+
+    /// int vs float
+    if constexpr (is_integer<A> && std::is_floating_point_v<B>) {
+        if constexpr (sizeof(A) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<B>(b).greater(a);
+    }
+
+    if constexpr (std::is_floating_point_v<A> && is_integer<B>) {
+        if constexpr (sizeof(B) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<A>(a).less(b);
+    }
+
+    static_assert(is_integer<A> || std::is_floating_point_v<A>);
+    static_assert(is_integer<B> || std::is_floating_point_v<B>);
+    __builtin_unreachable();
+}
+
+template <typename A, typename B>
+bool greaterOp(A a, B b) {
+    return lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool greaterOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(a, b);
+}
+
+template <typename A, typename B>
+bool lessOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool equalsOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a == b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a == b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
       if (is_nan(a) || is_nan(b)) { return false;
   }
   ```
   



##########
be/src/vec/core/accurate_comparison.h:
##########
@@ -464,6 +467,114 @@ template <typename A, typename B>
 inline bool_if_safe_conversion<A, B> greaterOrEqualsOp(A a, B b) {
     return a >= b;
 }
+*/
+
+template <typename A, typename B>
+bool lessOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a < b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a < b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a < b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a < 0 || static_cast<make_unsigned_t<A>>(a) < b;
+
+        if constexpr (!is_signed_v<A> && is_signed_v<B>)
+            return b >= 0 && a < static_cast<make_unsigned_t<B>>(b);
+    }
+
+    /// int vs float
+    if constexpr (is_integer<A> && std::is_floating_point_v<B>) {
+        if constexpr (sizeof(A) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<B>(b).greater(a);
+    }
+
+    if constexpr (std::is_floating_point_v<A> && is_integer<B>) {
+        if constexpr (sizeof(B) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<A>(a).less(b);
+    }
+
+    static_assert(is_integer<A> || std::is_floating_point_v<A>);
+    static_assert(is_integer<B> || std::is_floating_point_v<B>);
+    __builtin_unreachable();
+}
+
+template <typename A, typename B>
+bool greaterOp(A a, B b) {
+    return lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool greaterOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(a, b);
+}
+
+template <typename A, typename B>
+bool lessOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool equalsOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a == b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a == b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a == b;

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
           if constexpr (is_signed_v<A> == is_signed_v<B>) { return a == b;
   }
   ```
   



##########
be/src/vec/core/decimal_comparison.h:
##########
@@ -161,7 +170,7 @@ class DecimalComparison {
     static Shift getScales(const DataTypePtr& left_type, const DataTypePtr&) {
         Shift shift;
         const DataTypeDecimal<T>* decimal0 = check_decimal<T>(*left_type);
-        if (decimal0) shift.b = decimal0->get_scale_multiplier();
+        if (decimal0) shift.b = decimal0->get_scale_multiplier().value;

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
           if (decimal0) { shift.b = decimal0->get_scale_multiplier().value;
   }
   ```
   



##########
be/src/vec/core/decimal_comparison.h:
##########
@@ -53,6 +54,10 @@ template <>
 struct ConstructDecInt<16> {
     using Type = Int128;
 };
+template <>
+struct ConstructDecInt<32> {

Review Comment:
   warning: 32 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
   struct ConstructDecInt<32> {
                          ^
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
           if (rhs == 0) { return sign();
   }
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
           if (!isNegative() && rhs < 0) { return 1;
   }
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())
+                return rhs > 0 ? -1 : 1;
+            else
+                return rhs >= 0 ? -1 : 1;
+        }
+
+        /// The case of the most negative integer
+        if constexpr (is_signed_v<Int>) {
+            if (rhs == std::numeric_limits<Int>::lowest()) {
+                assert(isNegative());
+
+                if (normalizedExponent() < static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return 1;
+                if (normalizedExponent() > static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return -1;
+
+                if (mantissa() == 0)
+                    return 0;
+                else

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   ```cpp
                   else
                       ^
   ```
   this fix will not be applied because it overlaps with another fix



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())
+                return rhs > 0 ? -1 : 1;
+            else
+                return rhs >= 0 ? -1 : 1;
+        }
+
+        /// The case of the most negative integer
+        if constexpr (is_signed_v<Int>) {
+            if (rhs == std::numeric_limits<Int>::lowest()) {
+                assert(isNegative());
+
+                if (normalizedExponent() < static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))

Review Comment:
   warning: 8 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
                   if (normalizedExponent() < static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
                                                                   ^
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())
+                return rhs > 0 ? -1 : 1;
+            else
+                return rhs >= 0 ? -1 : 1;
+        }
+
+        /// The case of the most negative integer
+        if constexpr (is_signed_v<Int>) {
+            if (rhs == std::numeric_limits<Int>::lowest()) {
+                assert(isNegative());
+
+                if (normalizedExponent() < static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return 1;

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
                   if (normalizedExponent() < static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>)) {
                       return 1;
   }
   ```
   



##########
be/src/vec/core/decimal_comparison.h:
##########
@@ -170,7 +179,7 @@ class DecimalComparison {
     static Shift getScales(const DataTypePtr&, const DataTypePtr& right_type) {
         Shift shift;
         const DataTypeDecimal<U>* decimal1 = check_decimal<U>(*right_type);
-        if (decimal1) shift.a = decimal1->get_scale_multiplier();
+        if (decimal1) shift.a = decimal1->get_scale_multiplier().value;

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
           if (decimal1) { shift.a = decimal1->get_scale_multiplier().value;
   }
   ```
   



##########
be/src/vec/core/accurate_comparison.h:
##########
@@ -464,6 +467,114 @@ template <typename A, typename B>
 inline bool_if_safe_conversion<A, B> greaterOrEqualsOp(A a, B b) {
     return a >= b;
 }
+*/
+
+template <typename A, typename B>
+bool lessOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a < b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a < b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a < b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a < 0 || static_cast<make_unsigned_t<A>>(a) < b;
+
+        if constexpr (!is_signed_v<A> && is_signed_v<B>)
+            return b >= 0 && a < static_cast<make_unsigned_t<B>>(b);
+    }
+
+    /// int vs float
+    if constexpr (is_integer<A> && std::is_floating_point_v<B>) {
+        if constexpr (sizeof(A) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<B>(b).greater(a);
+    }
+
+    if constexpr (std::is_floating_point_v<A> && is_integer<B>) {
+        if constexpr (sizeof(B) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<A>(a).less(b);
+    }
+
+    static_assert(is_integer<A> || std::is_floating_point_v<A>);
+    static_assert(is_integer<B> || std::is_floating_point_v<B>);
+    __builtin_unreachable();
+}
+
+template <typename A, typename B>
+bool greaterOp(A a, B b) {
+    return lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool greaterOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(a, b);
+}
+
+template <typename A, typename B>
+bool lessOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool equalsOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a == b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a == b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a == b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a >= 0 && static_cast<make_unsigned_t<A>>(a) == b;
+
+        if constexpr (!is_signed_v<A> && is_signed_v<B>)
+            return b >= 0 && a == static_cast<make_unsigned_t<B>>(b);
+    }
+
+    /// int vs float
+    if constexpr (is_integer<A> && std::is_floating_point_v<B>) {
+        if constexpr (sizeof(A) <= 4) return static_cast<double>(a) == 
static_cast<double>(b);

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
           if constexpr (sizeof(A) <= 4) { return static_cast<double>(a) == 
static_cast<double>(b);
   }
   ```
   



##########
be/src/vec/core/accurate_comparison.h:
##########
@@ -464,6 +467,114 @@ template <typename A, typename B>
 inline bool_if_safe_conversion<A, B> greaterOrEqualsOp(A a, B b) {
     return a >= b;
 }
+*/
+
+template <typename A, typename B>
+bool lessOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a < b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a < b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a < b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a < 0 || static_cast<make_unsigned_t<A>>(a) < b;
+
+        if constexpr (!is_signed_v<A> && is_signed_v<B>)
+            return b >= 0 && a < static_cast<make_unsigned_t<B>>(b);
+    }
+
+    /// int vs float
+    if constexpr (is_integer<A> && std::is_floating_point_v<B>) {
+        if constexpr (sizeof(A) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<B>(b).greater(a);
+    }
+
+    if constexpr (std::is_floating_point_v<A> && is_integer<B>) {
+        if constexpr (sizeof(B) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<A>(a).less(b);
+    }
+
+    static_assert(is_integer<A> || std::is_floating_point_v<A>);
+    static_assert(is_integer<B> || std::is_floating_point_v<B>);
+    __builtin_unreachable();
+}
+
+template <typename A, typename B>
+bool greaterOp(A a, B b) {
+    return lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool greaterOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(a, b);
+}
+
+template <typename A, typename B>
+bool lessOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool equalsOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a == b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a == b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a == b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a >= 0 && static_cast<make_unsigned_t<A>>(a) == b;
+
+        if constexpr (!is_signed_v<A> && is_signed_v<B>)
+            return b >= 0 && a == static_cast<make_unsigned_t<B>>(b);
+    }
+
+    /// int vs float
+    if constexpr (is_integer<A> && std::is_floating_point_v<B>) {
+        if constexpr (sizeof(A) <= 4) return static_cast<double>(a) == 
static_cast<double>(b);
+
+        return DecomposedFloat<B>(b).equals(a);
+    }
+
+    if constexpr (std::is_floating_point_v<A> && is_integer<B>) {
+        if constexpr (sizeof(B) <= 4) return static_cast<double>(a) == 
static_cast<double>(b);

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
           if constexpr (sizeof(B) <= 4) { return static_cast<double>(a) == 
static_cast<double>(b);
   }
   ```
   



##########
be/src/vec/core/accurate_comparison.h:
##########
@@ -464,6 +467,114 @@ template <typename A, typename B>
 inline bool_if_safe_conversion<A, B> greaterOrEqualsOp(A a, B b) {
     return a >= b;
 }
+*/
+
+template <typename A, typename B>
+bool lessOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a < b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a < b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a < b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a < 0 || static_cast<make_unsigned_t<A>>(a) < b;
+
+        if constexpr (!is_signed_v<A> && is_signed_v<B>)
+            return b >= 0 && a < static_cast<make_unsigned_t<B>>(b);
+    }
+
+    /// int vs float
+    if constexpr (is_integer<A> && std::is_floating_point_v<B>) {
+        if constexpr (sizeof(A) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<B>(b).greater(a);
+    }
+
+    if constexpr (std::is_floating_point_v<A> && is_integer<B>) {
+        if constexpr (sizeof(B) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<A>(a).less(b);
+    }
+
+    static_assert(is_integer<A> || std::is_floating_point_v<A>);
+    static_assert(is_integer<B> || std::is_floating_point_v<B>);
+    __builtin_unreachable();
+}
+
+template <typename A, typename B>
+bool greaterOp(A a, B b) {
+    return lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool greaterOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(a, b);
+}
+
+template <typename A, typename B>
+bool lessOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool equalsOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a == b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a == b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a == b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a >= 0 && static_cast<make_unsigned_t<A>>(a) == b;
+
+        if constexpr (!is_signed_v<A> && is_signed_v<B>)

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   ```cpp
           if constexpr (!is_signed_v<A> && is_signed_v<B>)
                                                           ^
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);

Review Comment:
   warning: integer literal has suffix 'ull', which is not uppercase 
[readability-uppercase-literal-suffix]
   
   ```suggestion
           return int16_t(exponent()) - ((1ULL << (Traits::exponent_bits - 1)) 
- 1);
   ```
   



##########
be/src/vec/core/accurate_comparison.h:
##########
@@ -464,6 +467,114 @@ template <typename A, typename B>
 inline bool_if_safe_conversion<A, B> greaterOrEqualsOp(A a, B b) {
     return a >= b;
 }
+*/
+
+template <typename A, typename B>
+bool lessOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a < b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a < b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a < b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a < 0 || static_cast<make_unsigned_t<A>>(a) < b;
+
+        if constexpr (!is_signed_v<A> && is_signed_v<B>)
+            return b >= 0 && a < static_cast<make_unsigned_t<B>>(b);
+    }
+
+    /// int vs float
+    if constexpr (is_integer<A> && std::is_floating_point_v<B>) {
+        if constexpr (sizeof(A) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<B>(b).greater(a);
+    }
+
+    if constexpr (std::is_floating_point_v<A> && is_integer<B>) {
+        if constexpr (sizeof(B) <= 4) return static_cast<double>(a) < 
static_cast<double>(b);
+
+        return DecomposedFloat<A>(a).less(b);
+    }
+
+    static_assert(is_integer<A> || std::is_floating_point_v<A>);
+    static_assert(is_integer<B> || std::is_floating_point_v<B>);
+    __builtin_unreachable();
+}
+
+template <typename A, typename B>
+bool greaterOp(A a, B b) {
+    return lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool greaterOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(a, b);
+}
+
+template <typename A, typename B>
+bool lessOrEqualsOp(A a, B b) {
+    if (is_nan(a) || is_nan(b)) return false;
+
+    return !lessOp(b, a);
+}
+
+template <typename A, typename B>
+bool equalsOp(A a, B b) {
+    if constexpr (std::is_same_v<A, B>) return a == b;
+
+    /// float vs float
+    if constexpr (std::is_floating_point_v<A> && std::is_floating_point_v<B>) 
return a == b;
+
+    /// anything vs NaN
+    if (is_nan(a) || is_nan(b)) return false;
+
+    /// int vs int
+    if constexpr (is_integer<A> && is_integer<B>) {
+        /// same signedness
+        if constexpr (is_signed_v<A> == is_signed_v<B>) return a == b;
+
+        /// different signedness
+
+        if constexpr (is_signed_v<A> && !is_signed_v<B>)
+            return a >= 0 && static_cast<make_unsigned_t<A>>(a) == b;

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
           if constexpr (is_signed_v<A> && !is_signed_v<B>) {
               return a >= 0 && static_cast<make_unsigned_t<A>>(a) == b;
   }
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);

Review Comment:
   warning: integer literal has suffix 'ull', which is not uppercase 
[readability-uppercase-literal-suffix]
   
   ```suggestion
                  (((1ULL << (Traits::exponent_bits + 1)) - 1) >> 1);
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
               if (!isNegative()) {
   ```
   
   be/src/vec/core/decomposed_float.h:104:
   ```diff
   -             else
   +             } else
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }

Review Comment:
   warning: integer literal has suffix 'ull', which is not uppercase 
[readability-uppercase-literal-suffix]
   
   ```suggestion
       uint64_t mantissa() const { return x_uint & ((1ULL << 
Traits::mantissa_bits) - 1); }
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())
+                return rhs > 0 ? -1 : 1;
+            else

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   ```cpp
               else
                   ^
   ```
   this fix will not be applied because it overlaps with another fix



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())
+                return rhs > 0 ? -1 : 1;
+            else
+                return rhs >= 0 ? -1 : 1;

Review Comment:
   warning: do not use 'else' after 'return' [readability-else-after-return]
   
   ```suggestion
                               return rhs >= 0 ? -1 : 1;
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
           if (isNegative() && rhs > 0) { return -1;
   }
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())
+                return rhs > 0 ? -1 : 1;
+            else
+                return rhs >= 0 ? -1 : 1;
+        }
+
+        /// The case of the most negative integer
+        if constexpr (is_signed_v<Int>) {
+            if (rhs == std::numeric_limits<Int>::lowest()) {
+                assert(isNegative());
+
+                if (normalizedExponent() < static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return 1;
+                if (normalizedExponent() > static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))

Review Comment:
   warning: 8 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
                   if (normalizedExponent() > static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
                                                                   ^
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())
+                return rhs > 0 ? -1 : 1;
+            else
+                return rhs >= 0 ? -1 : 1;
+        }
+
+        /// The case of the most negative integer
+        if constexpr (is_signed_v<Int>) {
+            if (rhs == std::numeric_limits<Int>::lowest()) {
+                assert(isNegative());
+
+                if (normalizedExponent() < static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return 1;
+                if (normalizedExponent() > static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return -1;

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
                   if (normalizedExponent() > static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>)) {
                       return -1;
   }
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())
+                return rhs > 0 ? -1 : 1;
+            else
+                return rhs >= 0 ? -1 : 1;
+        }
+
+        /// The case of the most negative integer
+        if constexpr (is_signed_v<Int>) {
+            if (rhs == std::numeric_limits<Int>::lowest()) {
+                assert(isNegative());
+
+                if (normalizedExponent() < static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return 1;
+                if (normalizedExponent() > static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return -1;
+
+                if (mantissa() == 0)

Review Comment:
   warning: statement should be inside braces 
[readability-braces-around-statements]
   
   ```suggestion
                   if (mantissa() == 0) {
   ```
   
   be/src/vec/core/decomposed_float.h:120:
   ```diff
   -                 else
   +                 } else
   ```
   



##########
be/src/vec/core/decomposed_float.h:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/DecomposedFloat.h
+// and modified by Doris
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+
+#include "extended_types.h"
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template <typename T>
+struct FloatTraits;
+
+template <>
+struct FloatTraits<float> {
+    using UInt = uint32_t;
+    static constexpr size_t bits = 32;
+    static constexpr size_t exponent_bits = 8;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits<double> {
+    using UInt = uint64_t;
+    static constexpr size_t bits = 64;
+    static constexpr size_t exponent_bits = 11;
+    static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent 
- mantissa_bits))
+template <typename T>
+struct DecomposedFloat {
+    using Traits = FloatTraits<T>;
+
+    explicit DecomposedFloat(T x) { memcpy(&x_uint, &x, sizeof(x)); }
+
+    typename Traits::UInt x_uint;
+
+    bool isNegative() const { return x_uint >> (Traits::bits - 1); }
+
+    /// Returns 0 for both +0. and -0.
+    int sign() const { return (exponent() == 0 && mantissa() == 0) ? 0 : 
(isNegative() ? -1 : 1); }
+
+    uint16_t exponent() const {
+        return (x_uint >> (Traits::mantissa_bits)) &
+               (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+    }
+
+    int16_t normalizedExponent() const {
+        return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 
1);
+    }
+
+    uint64_t mantissa() const { return x_uint & ((1ull << 
Traits::mantissa_bits) - 1); }
+
+    int64_t mantissaWithSign() const { return isNegative() ? -mantissa() : 
mantissa(); }
+
+    /// NOTE Probably floating point instructions can be better.
+    bool isIntegerInRepresentableRange() const {
+        return x_uint == 0 ||
+               (normalizedExponent() >= 0 /// The number is not less than one
+                /// The number is inside the range where every integer has 
exact representation in float
+                && normalizedExponent() <= 
static_cast<int16_t>(Traits::mantissa_bits)
+                /// After multiplying by 2^exp, the fractional part becomes 
zero, means the number is integer
+                && ((mantissa() & ((1ULL << (Traits::mantissa_bits - 
normalizedExponent())) - 1)) ==
+                    0));
+    }
+
+    /// Compare float with integer of arbitrary width (both signed and 
unsigned are supported). Assuming two's complement arithmetic.
+    /// This function is generic, big integers (128, 256 bit) are supported as 
well.
+    /// Infinities are compared correctly. NaNs are treat similarly to 
infinities, so they can be less than all numbers.
+    /// (note that we need total order)
+    /// Returns -1, 0 or 1.
+    template <typename Int>
+    int compare(Int rhs) const {
+        if (rhs == 0) return sign();
+
+        /// Different signs
+        if (isNegative() && rhs > 0) return -1;
+        if (!isNegative() && rhs < 0) return 1;
+
+        /// Fractional number with magnitude less than one
+        if (normalizedExponent() < 0) {
+            if (!isNegative())
+                return rhs > 0 ? -1 : 1;
+            else
+                return rhs >= 0 ? -1 : 1;
+        }
+
+        /// The case of the most negative integer
+        if constexpr (is_signed_v<Int>) {
+            if (rhs == std::numeric_limits<Int>::lowest()) {
+                assert(isNegative());
+
+                if (normalizedExponent() < static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return 1;
+                if (normalizedExponent() > static_cast<int16_t>(8 * 
sizeof(Int) - is_signed_v<Int>))
+                    return -1;
+
+                if (mantissa() == 0)
+                    return 0;
+                else
+                    return -1;

Review Comment:
   warning: do not use 'else' after 'return' [readability-else-after-return]
   
   ```suggestion
                                       return -1;
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to