yiguolei commented on code in PR #28027:
URL: https://github.com/apache/doris/pull/28027#discussion_r1415384046
##########
be/src/vec/core/types.h:
##########
@@ -628,141 +676,19 @@ struct Decimal128I : public Decimal<Int128> {
}
};
-template <>
-struct Decimal<wide::Int256> {
- using T = wide::Int256;
- using NativeType = wide::Int256;
-
- Decimal() = default;
- Decimal(Decimal<T>&&) = default;
- Decimal(const Decimal<T>&) = default;
-
-#define DECLARE_NUMERIC_CTOR(TYPE) \
- explicit Decimal(const TYPE& value_) : value(value_) {}
-
- DECLARE_NUMERIC_CTOR(wide::Int256)
- DECLARE_NUMERIC_CTOR(Int128)
- DECLARE_NUMERIC_CTOR(Int32)
- DECLARE_NUMERIC_CTOR(Int64)
- DECLARE_NUMERIC_CTOR(UInt32)
- DECLARE_NUMERIC_CTOR(UInt64)
- DECLARE_NUMERIC_CTOR(Float32)
- DECLARE_NUMERIC_CTOR(Float64)
-
-#undef DECLARE_NUMERIC_CTOR
-
- static Decimal double_to_decimal(double value_) {
- DecimalV2Value decimal_value;
- decimal_value.assign_from_double(value_);
- return Decimal(binary_cast<DecimalV2Value, T>(decimal_value));
- }
-
- template <typename U>
- explicit Decimal(const Decimal<U>& x) {
- value = x.value;
- }
-
- constexpr Decimal<T>& operator=(Decimal<T>&&) = default;
- constexpr Decimal<T>& operator=(const Decimal<T>&) = default;
-
- operator T() const { return value; }
-
- operator Int128() const { return (Int128)value.items[0] +
((Int128)(value.items[1]) << 64); }
-
- const Decimal<T>& operator++() {
- value++;
- return *this;
- }
- const Decimal<T>& operator--() {
- value--;
- return *this;
- }
-
- const Decimal<T>& operator+=(const T& x) {
- value += x;
- return *this;
- }
- const Decimal<T>& operator-=(const T& x) {
- value -= x;
- return *this;
- }
- const Decimal<T>& operator*=(const T& x) {
- value *= x;
- return *this;
- }
- const Decimal<T>& operator/=(const T& x) {
- value /= x;
- return *this;
- }
- const Decimal<T>& operator%=(const T& x) {
- value %= x;
- return *this;
- }
-
- static constexpr int max_string_length() { return
max_decimal_string_length<T>(); }
-
- std::string to_string(UInt32 scale) const { return
decimal_to_string(value, scale); }
-
- /**
- * Got the string representation of a decimal.
- * @param dst Store the result, should be pre-allocated.
- * @param scale Decimal's scale.
- * @param scale_multiplier Decimal's scale multiplier.
- * @return The length of string.
- */
- __attribute__((always_inline)) size_t to_string(char* dst, UInt32 scale,
- const T& scale_multiplier)
const {
- return decimal_to_string(value, dst, scale, scale_multiplier);
- }
-
- T value;
-};
-
using Decimal32 = Decimal<Int32>;
using Decimal64 = Decimal<Int64>;
using Decimal128 = Decimal<Int128>;
using Decimal256 = Decimal<wide::Int256>;
-template <typename T>
-inline Decimal<T> operator-(const Decimal<T>& x) {
- return -x.value;
-}
-
-inline Decimal256 operator+(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value + y.value);
-}
-inline Decimal256 operator-(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value - y.value);
-}
-inline Decimal256 operator*(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value * y.value);
-}
-inline Decimal256 operator/(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value / y.value);
-}
-inline Decimal256 operator%(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value % y.value);
-}
-inline Decimal256 operator-(const Decimal256& x) {
- return Decimal256(-x.value);
-}
-inline bool operator<(const Decimal256& x, const Decimal256& y) {
- return x.value < y.value;
-}
-inline bool operator>(const Decimal256& x, const Decimal256& y) {
- return x.value > y.value;
-}
-inline bool operator<=(const Decimal256& x, const Decimal256& y) {
- return x.value <= y.value;
-}
-inline bool operator>=(const Decimal256& x, const Decimal256& y) {
- return x.value >= y.value;
-}
-inline bool operator==(const Decimal256& x, const Decimal256& y) {
- return x.value == y.value;
-}
-inline bool operator!=(const Decimal256& x, const Decimal256& y) {
- return x.value != y.value;
+inline std::strong_ordering operator<=>(const Decimal256& a, const Decimal256&
b) {
Review Comment:
not use <=>, the logic is not very clear.
And it is very dangerous.
##########
be/src/vec/core/types.h:
##########
@@ -628,141 +676,19 @@ struct Decimal128I : public Decimal<Int128> {
}
};
-template <>
-struct Decimal<wide::Int256> {
- using T = wide::Int256;
- using NativeType = wide::Int256;
-
- Decimal() = default;
- Decimal(Decimal<T>&&) = default;
- Decimal(const Decimal<T>&) = default;
-
-#define DECLARE_NUMERIC_CTOR(TYPE) \
- explicit Decimal(const TYPE& value_) : value(value_) {}
-
- DECLARE_NUMERIC_CTOR(wide::Int256)
- DECLARE_NUMERIC_CTOR(Int128)
- DECLARE_NUMERIC_CTOR(Int32)
- DECLARE_NUMERIC_CTOR(Int64)
- DECLARE_NUMERIC_CTOR(UInt32)
- DECLARE_NUMERIC_CTOR(UInt64)
- DECLARE_NUMERIC_CTOR(Float32)
- DECLARE_NUMERIC_CTOR(Float64)
-
-#undef DECLARE_NUMERIC_CTOR
-
- static Decimal double_to_decimal(double value_) {
- DecimalV2Value decimal_value;
- decimal_value.assign_from_double(value_);
- return Decimal(binary_cast<DecimalV2Value, T>(decimal_value));
- }
-
- template <typename U>
- explicit Decimal(const Decimal<U>& x) {
- value = x.value;
- }
-
- constexpr Decimal<T>& operator=(Decimal<T>&&) = default;
- constexpr Decimal<T>& operator=(const Decimal<T>&) = default;
-
- operator T() const { return value; }
-
- operator Int128() const { return (Int128)value.items[0] +
((Int128)(value.items[1]) << 64); }
-
- const Decimal<T>& operator++() {
- value++;
- return *this;
- }
- const Decimal<T>& operator--() {
- value--;
- return *this;
- }
-
- const Decimal<T>& operator+=(const T& x) {
- value += x;
- return *this;
- }
- const Decimal<T>& operator-=(const T& x) {
- value -= x;
- return *this;
- }
- const Decimal<T>& operator*=(const T& x) {
- value *= x;
- return *this;
- }
- const Decimal<T>& operator/=(const T& x) {
- value /= x;
- return *this;
- }
- const Decimal<T>& operator%=(const T& x) {
- value %= x;
- return *this;
- }
-
- static constexpr int max_string_length() { return
max_decimal_string_length<T>(); }
-
- std::string to_string(UInt32 scale) const { return
decimal_to_string(value, scale); }
-
- /**
- * Got the string representation of a decimal.
- * @param dst Store the result, should be pre-allocated.
- * @param scale Decimal's scale.
- * @param scale_multiplier Decimal's scale multiplier.
- * @return The length of string.
- */
- __attribute__((always_inline)) size_t to_string(char* dst, UInt32 scale,
- const T& scale_multiplier)
const {
- return decimal_to_string(value, dst, scale, scale_multiplier);
- }
-
- T value;
-};
-
using Decimal32 = Decimal<Int32>;
using Decimal64 = Decimal<Int64>;
using Decimal128 = Decimal<Int128>;
using Decimal256 = Decimal<wide::Int256>;
-template <typename T>
-inline Decimal<T> operator-(const Decimal<T>& x) {
- return -x.value;
-}
-
-inline Decimal256 operator+(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value + y.value);
-}
-inline Decimal256 operator-(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value - y.value);
-}
-inline Decimal256 operator*(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value * y.value);
-}
-inline Decimal256 operator/(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value / y.value);
-}
-inline Decimal256 operator%(const Decimal256& x, const Decimal256& y) {
- return Decimal256(x.value % y.value);
-}
-inline Decimal256 operator-(const Decimal256& x) {
- return Decimal256(-x.value);
-}
-inline bool operator<(const Decimal256& x, const Decimal256& y) {
- return x.value < y.value;
-}
-inline bool operator>(const Decimal256& x, const Decimal256& y) {
- return x.value > y.value;
-}
-inline bool operator<=(const Decimal256& x, const Decimal256& y) {
- return x.value <= y.value;
-}
-inline bool operator>=(const Decimal256& x, const Decimal256& y) {
- return x.value >= y.value;
-}
-inline bool operator==(const Decimal256& x, const Decimal256& y) {
- return x.value == y.value;
-}
-inline bool operator!=(const Decimal256& x, const Decimal256& y) {
- return x.value != y.value;
+inline std::strong_ordering operator<=>(const Decimal256& a, const Decimal256&
b) {
Review Comment:
not use <=>, the logic is not very clear.
And it is very dangerous.
--
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]