Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleFall committed Dec 8, 2022
1 parent d8c369c commit f2f7654
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dbms/src/Functions/divide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ struct TiDBDivideFloatingImpl<A, B, false>
template <typename Result = ResultType>
static Result apply(A a, B b)
{
return static_cast<Result>(a) / b;
if constexpr (std::is_integral_v<Result>)
return (static_cast<Result>(a) + b / 2) / b;
else
return static_cast<Result>(a) / b;
}
template <typename Result = ResultType>
static Result apply(A a, B b, UInt8 & res_null)
Expand All @@ -75,7 +78,7 @@ struct TiDBDivideFloatingImpl<A, B, false>
res_null = 1;
return static_cast<Result>(0);
}
return static_cast<Result>(a) / b;
return apply<Result>(a, b);
}
};

Expand All @@ -102,7 +105,7 @@ struct TiDBDivideFloatingImpl<A, B, true>
res_null = 1;
return static_cast<Result>(0);
}
return static_cast<Result>(a) / static_cast<Result>(b);
return apply<Result>(a, b);
}
};

Expand Down Expand Up @@ -332,4 +335,4 @@ void registerFunctionDivideIntegralOrZero(FunctionFactory & factory)
factory.registerFunction<FunctionDivideIntegralOrZero>();
}

} // namespace DB
} // namespace DB

0 comments on commit f2f7654

Please sign in to comment.