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

Fatal bug: sine()/cosine() calls taylorSeries(Ctor,0,x,x) with x=zero (d:[0] e:0 s:1) => infinite loop #132

Closed
Nibikibaba opened this issue Jun 10, 2019 · 2 comments

Comments

@Nibikibaba
Copy link

This would happen when toLessThanHalfPi() turns x to 'zero' in P.sin/P.cos (e.g. fractional part of the remainder after subtracting pi gives a number with e<minE) before calling taylorSeries() with that x.

Reproduction steps:
pi = Decimal.set({precision:30}).acos(-1);
s = Decimal.set({minE:-25}).sin(pi); //<-- calling cos() here would loop too.

  • There are not enough guards (or positioned incorrectly) in P.sin() or P.cos().
  • taylorSeries() should also check on its own to guard against infinite loops.

I am writing a simple calculator and was hoping that at least trivial cases like sin(pi) cos(pi) would return something less hairy like 5.2322..e-50 and hence the temporary changing of minE (misuse?)

@MikeMcl
Copy link
Owner

MikeMcl commented Jun 11, 2019

Yes, it's a bug, which only appears when an approximation of Pi is passed to sin or cos, and minE is low enough for the return value from toLessThanHalfPi to be zero. The sin and cos methods need to be amended to check for a zero result from toLessThanHalfPi.

Thanks for the report.

This bug doesn't appear in the current unpublished version of this library, which can be found here, in my last post. Therefore, this bug will be fixed when that version is finally published.

@MikeMcl
Copy link
Owner

MikeMcl commented Jun 22, 2021

Fixed in v10.3.0.

@MikeMcl MikeMcl closed this as completed Jun 22, 2021
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

No branches or pull requests

2 participants