Skip to content

[SPARK-55557][SQL][3.5] Hyperbolic functions should not overflow withlarge inputs#54803

Open
mgaido91 wants to merge 1 commit intoapache:branch-3.5from
mgaido91:SPARK-55557_3.5
Open

[SPARK-55557][SQL][3.5] Hyperbolic functions should not overflow withlarge inputs#54803
mgaido91 wants to merge 1 commit intoapache:branch-3.5from
mgaido91:SPARK-55557_3.5

Conversation

@mgaido91
Copy link
Contributor

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

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, NaN is returned.

How was this patch tested?

Added UTs.

Was this patch authored or co-authored using generative AI tooling?

No.

… 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>
@mgaido91
Copy link
Contributor Author

cc @peter-toth

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant