I'm working on a program that makes calculations in C++; one of which involves using the complete elliptic integral of the first kind.
Python and Mathematica produce these results
Python:
from scipy import special
print(special.ellipk(0.1))
print(special.ellipk(0.2))
print(special.ellipk(0.3))
with output
1.6124413487202192
1.659623598610528
1.713889448178791
Mathematica
EllipticK[0.1]
EllipticK[0.2]
EllipticK[0.3]
same output
1.61244
1.65962
1.71389
But in C++
#include <stdio.h>
#include <cmath>
int main()
{
printf("0.1 %f \n", std::comp_ellint_1(0.1));
printf("0.2 %f \n", std::comp_ellint_1(0.2));
printf("0.3 %f \n", std::comp_ellint_1(0.3));
return 0;
}
calculates different numbers
0.1 1.574746
0.2 1.586868
0.3 1.608049
It seems odd that there would be a mistake in C++'s standard cmath library. Is there a solution to this?
EDIT: When a small value (like 0.00001) is used, the numbers start to agree, so I think the issue is the calculation is an insufficient approximation. I am wondering if there is a version of this function for C++ that is as accurate as Mathematica or SciPy.

