Skip to content

Fix round() precision loss and errors for large Int64/UInt64 values#22927

Open
greedAuguria wants to merge 1 commit into
apache:mainfrom
greedAuguria:fix-round-large-int64-uint64
Open

Fix round() precision loss and errors for large Int64/UInt64 values#22927
greedAuguria wants to merge 1 commit into
apache:mainfrom
greedAuguria:fix-round-large-int64-uint64

Conversation

@greedAuguria

Copy link
Copy Markdown

Which issue does this PR close?

Closes #22696.

Rationale for this change

round() coerced integer inputs through Float64, which loses precision for Int64 values above 2^53 (round(9007199254740993) returned 9007199254740992.0) and errors outright for UInt64 values above i64::MAX (round(18446744073709551615) failed instead of being a no-op).

What changes are included in this PR?

Integers keep their own types through round(): the return type for integer inputs is the input type itself, making round(x) and round(x, n >= 0) identity-preserving for all integer values without a Float64 round-trip. Existing negative-scale rounding semantics and float behavior are preserved.

Are these changes tested?

Yes — regression tests added for both reported cases (cargo test -p datafusion-functions round: 8 passed, 0 failed).

Are there any user-facing changes?

round() on integer inputs now returns the integer input type instead of Float64.

round() previously coerced integer inputs through Float64, which loses
precision for Int64 values above 2^53 (round(9007199254740993) returned
9007199254740992.0) and errors outright for UInt64 values above
i64::MAX (round(18446744073709551615) failed instead of being a no-op).

Integers now keep their own types through round(): the return type for
integer inputs is the input type itself, making round(x) and
round(x, n >= 0) identity-preserving for all integer values without a
Float64 round-trip, while preserving the existing negative-scale
rounding semantics and float behavior.

Adds regression tests for both reported cases.

Fixes apache#22696
@github-actions github-actions Bot added the functions Changes to functions implementation label Jun 12, 2026
@Jefffrey

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

round() mishandles large Int64 and UInt64 values

2 participants