[SPARK-55557][SQL][3.5] Hyperbolic functions should not overflow withlarge inputs#54803
Open
mgaido91 wants to merge 1 commit intoapache:branch-3.5from
Open
[SPARK-55557][SQL][3.5] Hyperbolic functions should not overflow withlarge inputs#54803mgaido91 wants to merge 1 commit intoapache:branch-3.5from
mgaido91 wants to merge 1 commit intoapache:branch-3.5from
Conversation
… large inputs As mentioned in https://issues.apache.org/jira/browse/SPARK-55557, for large values (namely, larger than the square root of `Double.MAX:_VALUE`) the `asinh` and `acosh` functions return Infinity, due to overflow. This happens because of the `x * x` operation in the formula to compute them. However, for such large numbers, the expression can be simplified. Indeed, `x +\- 1` for such large numbers has no effect, since the precision is not enough to be sensitive to this operaiton. Hence, `log(x + sqrt(x * x +/- 1))` can be written as `log(2x) = (log(2) + log(x))` in such cases. Current code overflows and returns Infinity for asinh and acosh for large values. Yes, SQL with asinh and acosh with large values do not return infinity anymore. For large negative values as input of acosh, `NaN` is returned. Added UTs. No. Closes apache#54676 from mgaido91/SPARK-55557. Authored-by: Marco Gaido <mgaido@fbk.eu> Signed-off-by: Peter Toth <peter.toth@gmail.com>
Contributor
Author
|
cc @peter-toth |
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.
What changes were proposed in this pull request?
As mentioned in https://issues.apache.org/jira/browse/SPARK-55557, for large values (namely, larger than the square root of
Double.MAX:_VALUE) theasinhandacoshfunctions return Infinity, due to overflow. This happens because of thex * xoperation in the formula to compute them. However, for such large numbers, the expression can be simplified. Indeed,x +\- 1for such large numbers has no effect, since the precision is not enough to be sensitive to this operaiton. Hence,log(x + sqrt(x * x +/- 1))can be written aslog(2x) = (log(2) + log(x))in such cases.Why are the changes needed?
Current code overflows and returns Infinity for asinh and acosh for large values.
Does this PR introduce any user-facing change?
Yes, SQL with asinh and acosh with large values do not return infinity anymore. For large negative values as input of acosh,
NaNis returned.How was this patch tested?
Added UTs.
Was this patch authored or co-authored using generative AI tooling?
No.