YuvrajVerma09arch opened a new issue, #27787: URL: https://github.com/apache/datafusion/issues/27787
### Description `round` and `trunc` produce NaN for finite floating point inputs when the decimal precision is extreme. This was reproduced on main by a maintainer in closed PR 25741, which was closed under the AI Dump policy without merging, so the defect remains. ### Reproducer ```sql SELECT round(1.5::float, 40), round(1.5::float, -50); SELECT trunc(42.5::float, 40), trunc(42.5::float, -50); SELECT trunc(42.5::double, 2147483648); ``` Observed on current main, every result is NaN. Expected results are 1.5, 0.0, 42.5, 0.0 and 42.5 respectively. ### Root cause Both functions scale by a power of ten computed with `powi`. For large positive precision the factor overflows to infinity, so a finite value times infinity divided by infinity gives NaN. For large negative precision the factor underflows to zero, so zero divided by zero gives NaN. In `trunc` the i64 precision is also cast with `as i32`, so 2147483648 wraps to a large negative value and takes the underflow path. ### Proposed fix Check the computed factor. If it is infinite, return the original finite value. If it is zero, return zero with the sign of the input. Clamp i64 precision into the i32 range before calling `powi`. Add coverage for extreme positive and negative precision on both float32 and float64. This work is human supervised and task specific. AI assistance was used for codebase analysis and will be disclosed in any pull request. -- 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]
