fix: Avoid precision loss for atan2 with integer args#22516
Open
neilconway wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
atan2precision loss with integer arguments #22514.Rationale for this change
atan2defined two input signatures:(Float32, Float32)and(Float64, Float64)(in that order). That meant that integer inputs were coerced intoFloat32values, which lead to surprising results:atan2(1, 1000000)resulted in less precision thanatan2(1.0, 1000000.0); the results for the former were also inconsistent with the behavior ofatan2in Postgres and DuckDB.We could fix this by preferring
Float64inputs, but it seems simpler to just removeFloat32entirely. This matches the approach taken by most SQL implementations (Postgres, DuckDB, Snowflake, Spark SQL, etc.)What changes are included in this PR?
make_math_binary_udfto assumeFloat64inputs and outputs (atan2is the only caller)Float32case fromatan2benchmarksAre these changes tested?
Yes, new test added.
Are there any user-facing changes?
Yes;
atan2will be computed in double precision in all cases now and will never returnFloat32.