Bugfix for nagating decimal_int
This commit is contained in:
@ -510,31 +510,23 @@ inline bool is_zero(const ObDecimalInt *decint, int32_t int_bytes)
|
||||
}
|
||||
|
||||
inline int negate(const ObDecimalInt *decint, int32_t int_bytes, ObDecimalInt *&out_decint,
|
||||
ObIAllocator &allocator)
|
||||
int32_t out_bytes, ObIAllocator &allocator)
|
||||
{
|
||||
#define NEG_VAL_CASE(int_type) \
|
||||
case sizeof(int_type): { \
|
||||
*reinterpret_cast<int_type *>(out_decint) = -(*reinterpret_cast<const int_type *>(decint)); \
|
||||
} break
|
||||
#define DO_NEG_VAL(in_type, out_type)\
|
||||
*reinterpret_cast<out_type *>(out_decint) = -(*reinterpret_cast<const in_type *>(decint));
|
||||
|
||||
int ret = OB_SUCCESS;
|
||||
out_decint = nullptr;
|
||||
if (int_bytes == 0) {
|
||||
if (out_bytes == 0 || int_bytes == 0) {
|
||||
// do nothing
|
||||
} else if (OB_ISNULL(out_decint = (ObDecimalInt *)allocator.alloc(int_bytes))) {
|
||||
} else if (OB_ISNULL(out_decint = (ObDecimalInt *)allocator.alloc(out_bytes))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
SQL_LOG(WARN, "allocate memory failed", K(ret));
|
||||
} else {
|
||||
switch (int_bytes) {
|
||||
LST_DO_CODE(NEG_VAL_CASE, int32_t, int64_t, int128_t, int256_t, int512_t);
|
||||
default: {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_LOG(WARN, "unexpected int bytes", K(ret), K(int_bytes));
|
||||
}
|
||||
}
|
||||
DISPATCH_INOUT_WIDTH_TASK(int_bytes, out_bytes, DO_NEG_VAL);
|
||||
}
|
||||
return ret;
|
||||
#undef NEG_VAL_CASE
|
||||
#undef DO_NEG_VAL
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
Reference in New Issue
Block a user