elliptic-integrals-js icon indicating copy to clipboard operation
elliptic-integrals-js copied to clipboard

Consider adding some zero checks

Open JohannesMP opened this issue 7 years ago • 1 comments

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.

JohannesMP avatar Jul 18 '18 04:07 JohannesMP

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

duetosymmetry avatar Jul 18 '18 13:07 duetosymmetry