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

Consider adding some zero checks #1

Open
JohannesMP opened this issue Jul 18, 2018 · 1 comment
Open

Consider adding some zero checks #1

JohannesMP opened this issue Jul 18, 2018 · 1 comment

Comments

@JohannesMP
Copy link

JohannesMP commented Jul 18, 2018

Disclaimer: I'm no Mathematician; Just a random programmer that stumbled on this repo while looking for an EllipticE implementation to use with Ellipses.

I noticed that if the m is passed into EllipticE is 1, as in the case when solving for the Perimeter of an Ellipse with a SemiMinor axis of 0 (or very close to it), the function can fail to converge in time despite the result being trivial.

In my implementation I added a check for the same epsilon you used to verify an-gn in the while loop:

...
var kprime = Math.sqrt(1. - m);
if(kprime < 1e-15)
    return 1;
...

I'm not sure if any similar checks could be added to avoid unnecessarily iterations in cases where we know what the answer should be, or if my approach here was even valid, but it resolved an edge case for me at least.

@duetosymmetry
Copy link
Owner

Thanks for the interest, @JohannesMP. If you create a pull request, I'll happily review it!

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