Pastoray commented on PR #435:
URL: https://github.com/apache/datafusion-spark/pull/435#issuecomment-7393665153

   Thanks, this was useful. I reproduced every row of your table against Java 
21 and Spark 4.2.0, and the root cause is broader than #433: Rust rounds the 
binary value half-even after a floating-point division, while Java rounds the 
decimal digits half-up. So I took the digit-based approach in this PR rather 
than filing a separate issue.
   
   **What changed.** `scientific_digits` takes the shortest round-trip digits 
(`format!("{abs:e}")`), rounds them half-up to the precision, carries into the 
exponent and pads with zeros. That also answers your other two points. The 
mantissa is no longer formatted twice, and the subnormal case is fixed because 
there is no `10^exp` to underflow (`%e` of `1e-310` is now `1.000000e-310`).
   
   **Checks.**
   - I compared 26,260 results against `java.util.Formatter` across 13 formats 
and about 2,000 values (random, ties, carries, subnormals, extremes). The 
`%e`/`%E` family goes from 2,314 mismatches to 191, with no regressions. 8 of 
the 191 are `4.9e-324` and the other 183 are `%g` mismatches that are identical 
before and after.
   - The new records fail on the previous commit and pass now. All 15 
scientific-notation records pass the repo's PySpark runner on Spark 4.2.0 and 
3.5.9.
   - `cargo test`, `fmt` and `clippy` pass.
   
   **The one known difference.** `4.9e-324` is the lone remaining mismatch on 
the `%e` family: Java's own digits for it aren't the shortest, so we print 
`5.000000e-324` (Spark: `4.900000e-324`). I left it out of the tests.
   
   **Out of scope, found by the same test.** `%g` has its own rounding 
mismatches that this PR doesn't touch, for example `%.3g` of `9.325` gives 
`9.32` (Java `9.33`), and values near the double limits give `NaN` or 
`0.00e+00`. I'll open a separate issue for that.
   
   **Other PRs.** #416 merges cleanly with this one. #427 conflicts in the 
scientific branch, as you expected; resolving it is mechanical (`number = 
mantissa;`, then #427's `#` lines, then the exponent). With all of them 
together the suite passes and `%#.0e` of `9.9999999` gives `1.e+01`. Whichever 
of #427 and this lands second can add that record.


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