bigdecimal icon indicating copy to clipboard operation
bigdecimal copied to clipboard

Add support for tangent function

Open rhannequin opened this issue 2 years ago • 12 comments

Associated issue: #81

Context

BigMath module supports sine (sin) and cosine (cos) trigonometric functions. It also supports arctangent (acan). But it doesn't support tangent, which is supported in Math module.

Solution

tan is related to sin and cos function such as (source):

tan(x) = sin(x) / cos(x)

This PR adds BigMath.tan(x, precision), dependent on existing BigMath.sin and BigMath.cos methods.

rhannequin avatar Jun 28 '22 20:06 rhannequin

Hello @mrkn, anything I should do to this PR to improve it? Please let me know if I missed a step to have this PR reviewed 🙏 Thank you.

rhannequin avatar Jul 25 '22 12:07 rhannequin

I'm working on supporting BigDecimal in assert_in_delta family assertions at https://github.com/test-unit/test-unit/pull/218.

mrkn avatar Sep 25 '22 12:09 mrkn

I'm working on adding tests with higher precision at https://github.com/ruby/bigdecimal/pull/238

mrkn avatar Oct 08 '22 02:10 mrkn

@mrkn Hello, I'm back after a small break. Maybe I can help with #238?

rhannequin avatar Oct 15 '22 20:10 rhannequin

@rhannequin Although test-unit now supports BigDecimal in assert_in_delta family assertions, as tests of BigDecimal need to run also in Ruby's test-all, I have to let the test framework in Ruby's test-all support the new assert_in_delta family assertions.

Until finishing this work, could you try to rewrite tan implementation to depend on only sin?

mrkn avatar Oct 15 '22 23:10 mrkn

Hello @mrkn, I hope you're doing great.

I did some research for a new algorithm for cos and arrived to the conclusion to just duplicate it, for now, so that tan only depends on sin.

I committed it a few minutes ago, what do you think?

rhannequin avatar Oct 30 '22 13:10 rhannequin

@mrkn Hello, sorry for taking so long to move forward with this pull request.

My math background is not really advanced and I wasn't familiar with this definition of cosine based on sine. I changed the implementation of tan to only depend on sin with this new definition, which is indeed much clearer and probably much faster.

Would you still like a link to a paper or an "official" definition for the documentation?

rhannequin avatar Feb 16 '24 09:02 rhannequin

@hsbt I allow myself to ping you here as you seem to have been active on the project recently. Please let me know if this PR needs to be reviewed by someone in particular, or if anything must be changed in the content.

rhannequin avatar Feb 21 '24 21:02 rhannequin

@rhannequin He’s recent work is only for leaving this library out of Ruby’s default gems. I think there are few people who can review new features of bigdecimal in the Ruby core team. Could you please wait until I can look into your new commits?

mrkn avatar Feb 22 '24 00:02 mrkn

Absolutely, @mrkn. Sorry if my comment sounded pressing, I wasn't sure you had time for this at the moment. I'll wait now all the time needed.

rhannequin avatar Feb 22 '24 05:02 rhannequin

@rhannequin Thank you for your understanding and cooperation!

mrkn avatar Feb 22 '24 08:02 mrkn