slfan1989 commented on issue #1327: URL: https://github.com/apache/auron/issues/1327#issuecomment-3383801818
I’m continuing to follow up on this issue and have completed part of the research work. I’m sharing the relevant information below to help clarify what improvements we need to make. > Spark We can refer to the mathExpressions.scala class, where the Round function uses the ROUND_HALF_UP algorithm. https://github.com/apache/spark/blob/18f0463a97bde206595a0a0d3a8c2b6d37d38975/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala#L1704-L1727 ``` @ExpressionDescription( usage = "_FUNC_(expr, d) - Returns `expr` rounded to `d` decimal places using HALF_UP rounding mode.", examples = """ Examples: > SELECT _FUNC_(2.5, 0); 3 """, since = "1.5.0", group = "math_funcs") // scalastyle:on line.size.limit case class Round( child: Expression, scale: Expression, override val ansiEnabled: Boolean = SQLConf.get.ansiEnabled) extends RoundBase(child, scale, BigDecimal.RoundingMode.HALF_UP, "ROUND_HALF_UP") { def this(child: Expression) = this(child, Literal(0), SQLConf.get.ansiEnabled) def this(child: Expression, scale: Expression) = this(child, scale, SQLConf.get.ansiEnabled) override def flatArguments: Iterator[Any] = Iterator(child, scale) override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Round = copy(child = newLeft, scale = newRight) } ``` > DataFushion [round.rs](https://github.com/apache/datafusion/blob/main/datafusion/functions/src/math/round.rs) For example, the implementation of Float64: ``` (value * 10.0_f64.powi(decimal_places)).round() / 10.0_f64.powi(decimal_places) ``` The core here is: ``` f64::round() ``` The definition of `f64::round()` in the Rust standard library is: [Doc](https://doc.rust-lang.org/std/primitive.f64.html#method.round) ``` Returns the nearest integer to a number. Rounds halfway cases away from zero. ``` So from an algorithmic perspective, the two should be consistent, and we need to look at some differences from specific cases. -- 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]
