jacktengg commented on code in PR #67965:
URL: https://github.com/apache/doris/pull/67965#discussion_r4011126211
##########
be/src/exprs/function/cast/cast_to_decimal.h:
##########
@@ -246,45 +246,63 @@ struct CastToDecimal {
"to decimal");
return false;
}
- using DoubleType = std::conditional_t<IsDecimal256<ToCppT>, long
double, double>;
- DoubleType tmp = from * static_cast<DoubleType>(scale_multiplier);
- if (tmp <= DoubleType(min_result) || tmp >= DoubleType(max_result)) {
+ auto overflow = [&]() {
if (params.is_strict) {
params.status = DECIMAL_CONVERT_OVERFLOW_ERROR(from,
"float/double", to_precision,
to_scale);
}
return false;
+ };
+ using DoubleType = std::conditional_t<IsDecimal256<ToCppT>, long
double, double>;
+ // Round before checking the inclusive decimal bounds. Adding 0.5
would itself round
+ // exactly representable odd integers above 2^52 to the next even
integer in double.
Review Comment:
fixed
--
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]