hello-stephen commented on code in PR #71094:
URL: https://github.com/apache/doris/pull/71094#discussion_r4756590163


##########
be/src/exprs/function/round.h:
##########
@@ -476,6 +586,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 precision before deciding negative-scale ties
   
   For a stored DOUBLE `x = 3.323069989462296e35`, `round(x, -20)` now returns 
`3.323069989462297e35`, one ULP too large. The exact quotient by `1e20` is 
`3323069989462296.323087...`, but `Base::divide` first rounds it to DOUBLE 
`3323069989462296.5`, so ROUND chooses the wrong multiple. Here `1e20` exceeds 
half the input ULP, so the new identity guard does not apply. The base and 
FE-folded literal both retain `x`; `round_bankers` likewise fails for `x = 
3.323069989462299e35`. Keep sufficient precision through scaling and the tie 
decision, and cover these boundaries across the dispatcher shapes.



-- 
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]

Reply via email to