Skip to content

Conversation

@CAJan93
Copy link
Contributor

@CAJan93 CAJan93 commented Mar 31, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Implement the following functions:

sinh / cosh / tanh / asinh / acosh / atanh

There is no atan2h AFAIK.

tracking issue: #8806 #9675

Checklist For Contributors

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • I have demonstrated that backward compatibility is not broken by breaking changes and created issues to track deprecated features to be removed in the future. (Please refer to the issue)
  • All checks passed in ./risedev check (or alias, ./risedev c)

Checklist For Reviewers

  • I have requested macro/micro-benchmarks as this PR can affect performance substantially, and the results are shown.

Documentation

Documents are here: #9675

Types of user-facing changes

Please keep the types that apply to your changes, and remove the others.

  • SQL commands, functions, and operators

Release note

Implement hyperbolic trigonometric functions.

@github-actions github-actions bot added the type/feature Type: New feature. label Mar 31, 2023
Copy link
Contributor

@xiangjinwu xiangjinwu left a comment

Choose a reason for hiding this comment

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

btw we can remove the leading --@ of the following tests now:

-- test Inf/NaN cases for hyperbolic functions
--@ SELECT sinh(double precision 'infinity');
--@ SELECT sinh(double precision '-infinity');
--@ SELECT sinh(double precision 'nan');
--@ SELECT cosh(double precision 'infinity');
--@ SELECT cosh(double precision '-infinity');
--@ SELECT cosh(double precision 'nan');
--@ SELECT tanh(double precision 'infinity');
--@ SELECT tanh(double precision '-infinity');
--@ SELECT tanh(double precision 'nan');
--@ SELECT asinh(double precision 'infinity');
--@ SELECT asinh(double precision '-infinity');
--@ SELECT asinh(double precision 'nan');
-- acosh(Inf) should be Inf, but some mingw versions produce NaN, so skip test
-- SELECT acosh(double precision 'infinity');
--@ SELECT acosh(double precision '-infinity');
--@ SELECT acosh(double precision 'nan');
--@ SELECT atanh(double precision 'infinity');
--@ SELECT atanh(double precision '-infinity');
--@ SELECT atanh(double precision 'nan');

proto/expr.proto Outdated
SINH = 261;
COSH = 262;
TANH = 263;
COTH = 264;
Copy link
Contributor

Choose a reason for hiding this comment

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

t

query R
SELECT abs(sinh(1) - 1.1752011936438014) < 0.000000000000001
Copy link
Contributor

Choose a reason for hiding this comment

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

Equality of imprecise float is inherently hard 😢 FYI postgres regress test only test for 15 significant decimal digits for double precision, using the extra_float_digits config we do not support yet.

-- hyperbolic functions
-- we run these with extra_float_digits = 0 too, since different platforms
-- tend to produce results that vary in the last place.
SELECT sinh(double precision '1');
sinh
-----------------
1.1752011936438
(1 row)

But we can manually adjust the precision requirement here, and we have no intention to do better than rust builtin f64::sinh...

What about

SELECT abs(sinh(1) - 1.17520119364380) < 1e-15;
-- or even 1e-14 if the ci machine is less capable

btw it is also a bit clearer to use the 1e-15 syntax rather than counting the zeros.

@neverchanje neverchanje added the user-facing-changes Contains changes that are visible to users label May 9, 2023
@neverchanje neverchanje linked an issue May 9, 2023 that may be closed by this pull request
@CAJan93 CAJan93 closed this May 9, 2023
@CAJan93 CAJan93 reopened this May 9, 2023
@CAJan93
Copy link
Contributor Author

CAJan93 commented May 10, 2023

Sorry for not coming back to this earlier. I updated the PR according to your suggestions. Thank you very much for your comments @xiangjinwu.

@codecov
Copy link

codecov bot commented May 10, 2023

Codecov Report

Merging #8918 (9bd5a5d) into main (9de9d69) will increase coverage by 0.00%.
The diff coverage is 93.58%.

@@           Coverage Diff           @@
##             main    #8918   +/-   ##
=======================================
  Coverage   71.12%   71.12%           
=======================================
  Files        1250     1250           
  Lines      209294   209371   +77     
=======================================
+ Hits       148850   148924   +74     
- Misses      60444    60447    +3     
Flag Coverage Δ
rust 71.12% <93.58%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/frontend/src/expr/pure.rs 95.00% <ø> (ø)
src/expr/src/vector_op/trigonometric.rs 96.35% <92.95%> (-0.62%) ⬇️
src/frontend/src/binder/expr/function.rs 88.26% <100.00%> (+0.12%) ⬆️

... and 7 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@xiangjinwu xiangjinwu left a comment

Choose a reason for hiding this comment

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

As mentioned in earlier comments, could you turn on the applicable regress tests?

proto/expr.proto Outdated
Comment on lines 114 to 120
SINH = 253;
COSH = 254;
TANH = 255;
COTH = 256;
ASINH = 257;
ACOSH = 258;
ATANH = 259;
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI it would not be backward compatible when we change the mapping of an existing enum value.

@neverchanje neverchanje requested a review from xxchan May 11, 2023 03:34
@CAJan93 CAJan93 requested a review from xiangjinwu May 12, 2023 08:41
@xiangjinwu xiangjinwu mentioned this pull request May 12, 2023
7 tasks
@CAJan93 CAJan93 enabled auto-merge May 12, 2023 09:45
@CAJan93 CAJan93 disabled auto-merge May 12, 2023 09:47
@CAJan93 CAJan93 enabled auto-merge May 12, 2023 09:54
@CAJan93 CAJan93 added this pull request to the merge queue May 18, 2023
Merged via the queue into main with commit ed2b900 May 18, 2023
@CAJan93 CAJan93 deleted the trig_h_funcs branch May 18, 2023 11:47
@CharlieSYH CharlieSYH added the 📖✓ Covered or will be covered in the user docs. label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/feature Type: New feature. user-facing-changes Contains changes that are visible to users 📖✓ Covered or will be covered in the user docs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement functions: sinh / cosh / tanh / asinh / acosh / atanh

5 participants