Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SQL] Add hyperbolic functions #1280

Merged
merged 3 commits into from
Jan 18, 2024
Merged

[SQL] Add hyperbolic functions #1280

merged 3 commits into from
Jan 18, 2024

Conversation

abhizer
Copy link
Contributor

@abhizer abhizer commented Jan 18, 2024

Is this a user-visible change (yes/no): yes

Partially fixes: #1265

@abhizer abhizer added documentation Improvements or additions to documentation SQL compiler Related to the SQL compiler labels Jan 18, 2024
@abhizer abhizer added this to the Jan 23, 2024 milestone Jan 18, 2024
1.5430806348152437
(1 row)

SELECT coth(0.6); -- not tested in Spark
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't available in Spark.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have said "not available in Spark"

#[inline(always)]
pub fn sec_d(value: F64) -> F64 {
let cos = value.into_inner().cos();
if cos.is_zero() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust doesn't have sec?
Also, if you just do the division with 0 don't you get the same result?
Or maybe the result can be -infinity sometimes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually yeah, its Infinity even if we divide by 0. I was expecting a division by 0 error, but turns out it gives inf if the number being divided is positive and -inf if the number being divided is negative.

if tanh.is_zero() {
f64::INFINITY.into()
} else {
(1.0 / tanh).into()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question about division

pub fn atanh_d(value: F64) -> F64 {
let inner = value.into_inner();
if !(-1.0..=1.0).contains(&inner) && !inner.is_nan() {
panic!("input out of range")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error message should probably be more informative, including the actual value and the range.
we'll also add position at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, will add the value to the error message.

Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
* Remove unnecessary check for zero

Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
@mihaibudiu
Copy link
Collaborator

Did proptest find a bug here?

@mihaibudiu mihaibudiu merged commit 43fe53d into main Jan 18, 2024
2 of 3 checks passed
@mihaibudiu mihaibudiu deleted the hyperbolic_functions branch January 18, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation SQL compiler Related to the SQL compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SQL] Missing SQL functions
2 participants