22
22
23
23
#include " vec/columns/column_const.h"
24
24
#include " vec/columns/columns_number.h"
25
+ #include " vec/exec/format/format_common.h"
25
26
#include " vec/functions/function.h"
26
27
#if defined(__SSE4_1__) || defined(__aarch64__)
27
28
#include " util/sse_util.hpp"
28
29
#else
29
30
#include < fenv.h>
30
31
#endif
31
32
#include < algorithm>
33
+ #include < type_traits>
32
34
33
35
#include " vec/columns/column.h"
34
36
#include " vec/columns/column_decimal.h"
@@ -64,7 +66,7 @@ enum class TieBreakingMode {
64
66
};
65
67
66
68
template <typename T, RoundingMode rounding_mode, ScaleMode scale_mode,
67
- TieBreakingMode tie_breaking_mode>
69
+ TieBreakingMode tie_breaking_mode, typename U >
68
70
struct IntegerRoundingComputation {
69
71
static const size_t data_count = 1 ;
70
72
@@ -116,7 +118,7 @@ struct IntegerRoundingComputation {
116
118
__builtin_unreachable ();
117
119
}
118
120
119
- static ALWAYS_INLINE T compute (T x, T scale, size_t target_scale) {
121
+ static ALWAYS_INLINE T compute (T x, T scale, T target_scale) {
120
122
switch (scale_mode) {
121
123
case ScaleMode::Zero:
122
124
case ScaleMode::Positive:
@@ -128,10 +130,10 @@ struct IntegerRoundingComputation {
128
130
__builtin_unreachable ();
129
131
}
130
132
131
- static ALWAYS_INLINE void compute (const T* __restrict in, size_t scale, T* __restrict out,
132
- size_t target_scale) {
133
+ static ALWAYS_INLINE void compute (const T* __restrict in, U scale, T* __restrict out,
134
+ U target_scale) {
133
135
if constexpr (sizeof (T) <= sizeof (scale) && scale_mode == ScaleMode::Negative) {
134
- if (scale > size_t ( std::numeric_limits<T>::max () )) {
136
+ if (scale >= std::numeric_limits<T>::max ()) {
135
137
*out = 0 ;
136
138
return ;
137
139
}
@@ -145,23 +147,24 @@ class DecimalRoundingImpl {
145
147
private:
146
148
using NativeType = typename T::NativeType;
147
149
using Op = IntegerRoundingComputation<NativeType, rounding_mode, ScaleMode::Negative,
148
- tie_breaking_mode>;
150
+ tie_breaking_mode, NativeType >;
149
151
using Container = typename ColumnDecimal<T>::Container;
150
152
151
153
public:
152
154
static NO_INLINE void apply (const Container& in, UInt32 in_scale, Container& out,
153
155
Int16 out_scale) {
154
156
Int16 scale_arg = in_scale - out_scale;
155
157
if (scale_arg > 0 ) {
156
- size_t scale = int_exp10 (scale_arg);
158
+ auto scale = DecimalScaleParams::get_scale_factor<NativeType> (scale_arg);
157
159
158
160
const NativeType* __restrict p_in = reinterpret_cast <const NativeType*>(in.data ());
159
161
const NativeType* end_in = reinterpret_cast <const NativeType*>(in.data ()) + in.size ();
160
162
NativeType* __restrict p_out = reinterpret_cast <NativeType*>(out.data ());
161
163
162
164
if (out_scale < 0 ) {
165
+ auto negative_scale = DecimalScaleParams::get_scale_factor<NativeType>(-out_scale);
163
166
while (p_in < end_in) {
164
- Op::compute (p_in, scale, p_out, int_exp10 (-out_scale) );
167
+ Op::compute (p_in, scale, p_out, negative_scale );
165
168
++p_in;
166
169
++p_out;
167
170
}
@@ -320,7 +323,7 @@ template <typename T, RoundingMode rounding_mode, ScaleMode scale_mode,
320
323
TieBreakingMode tie_breaking_mode>
321
324
struct IntegerRoundingImpl {
322
325
private:
323
- using Op = IntegerRoundingComputation<T, rounding_mode, scale_mode, tie_breaking_mode>;
326
+ using Op = IntegerRoundingComputation<T, rounding_mode, scale_mode, tie_breaking_mode, size_t >;
324
327
using Container = typename ColumnVector<T>::Container;
325
328
326
329
public:
0 commit comments