hello-stephen commented on code in PR #71094:
URL: https://github.com/apache/doris/pull/71094#discussion_r4742366267
##########
be/src/exprs/function/round.h:
##########
@@ -476,6 +573,34 @@ struct Dispatcher {
FloatRoundingImpl<T, rounding_mode, scale_mode,
tie_breaking_mode>,
IntegerRoundingImpl<T, rounding_mode, scale_mode,
tie_breaking_mode>>>;
+ template <typename Input, typename Output>
+ static void apply_positive(const Input& in, Int32 precision, Output& out) {
+ if constexpr (is_float_or_double(T) || T == TYPE_TIMEV2) {
+ using Value = typename PrimitiveTypeTraits<T>::CppType;
+ if (precision > std::numeric_limits<Value>::max_exponent10) {
+ // Do not lose the precision by passing an infinite factor to
the scalar path.
+
FunctionRoundingImpl<ScaleMode::Positive>::apply_large_positive_scale(in,
precision,
+
out);
+ return;
+ }
+ }
+ auto scale = scale_factor(precision);
+ FunctionRoundingImpl<ScaleMode::Positive>::apply(in, scale, out);
+ }
+
+ static auto scale_factor(Int32 exponent) {
+ if constexpr (is_float_or_double(T) || T == TYPE_TIMEV2) {
+ // Keep the table lookup for common scales. 10^20 no longer fits
in uint64,
+ // so larger floating factors must not use int_exp10's saturation.
+ if (exponent <= 19) {
+ return static_cast<double>(int_exp10(exponent));
+ }
+ return std::pow(10.0, exponent);
Review Comment:
[P2] Preserve exact DOUBLE inputs at large positive precisions
For a DOUBLE column containing `47.5`, `round(x, 20)` now returns
`47.50000000000001`: the new `1e20` factor is exact, but `47.5 * 1e20` rounds
to `4750000000000000524288`, which is already integral, and dividing back
introduces one ULP. Rounding exact `47.5` to 20 decimal places must retain
`47.5`; the base preserved it because the saturated factor converted to exact
`2^64`. This affects all five rounding modes and all dispatcher shapes; FE
folding of the literal still returns `47.5`, so equality predicates can now
depend on whether the value is a column. Preserve the input when the requested
unit cannot change its representable value, or use sufficient intermediate
precision, and add exact-equality coverage for this case.
##########
be/src/exprs/function/round.h:
##########
@@ -349,8 +413,41 @@ struct FloatRoundingImpl {
using ColumnType = ColumnVector<Type>;
using Container = typename ColumnType::Container;
+ static long double decimal_unit(Int32 precision) {
+ // At 324 places for DOUBLE, or 46 for FLOAT, one decimal unit is less
+ // than half the smallest representable value. Rounding keeps the
input.
+ constexpr int unchanged_precision =
+ std::numeric_limits<T>::max_digits10 -
std::numeric_limits<T>::min_exponent10;
+ return precision >= unchanged_precision ? 0 : std::pow(10.0L,
-precision);
Review Comment:
[P2] Avoid the narrowing AArch64 compatibility powl
On the default Linux AArch64 build, this new long-double power uses Doris's
compatibility `powl`: `be/src/glibc-compatibility/musl/powl.c:519-525`
implements the 113-bit branch with `return pow(x, y)`, narrowing both arguments
and the result to DOUBLE. The compatibility archive includes this file and
precedes `-lm` (`be/src/glibc-compatibility/CMakeLists.txt:25-33`,
`be/CMakeLists.txt:869-889`). Consequently, precision `323` produces a unit of
exactly `2 * DOUBLE_DENORM_MIN`; for `round(DOUBLE_DENORM_MIN, 323)`, the
quotient is exactly `0.5` and `std::round` returns one unit, rather than the
required zero (the true decimal quotient is about `0.494`). This also makes the
new `FloatingPositiveRoundingScale` test fail on that platform. Compute the
unit with an implementation that retains long-double precision on AArch64, or
fix the compatibility implementation, and cover that build.
--
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]