19static double ceiAccuracy = 1e-14;
21void setCeiAccuracy(
double newAccuracy) {
22 ceiAccuracy = newAccuracy;
34 double a0, b0, c0, a1, b1;
37 b0 = sqrt(1 - sqr(k));
47 }
while (fabs(c0) > ceiAccuracy);
60 double a0, b0, c0, a1, b1, c1, K, sum, powerOf2;
63 b0 = sqrt(1 - sqr(k));
73 sum += sqr(c1) * (powerOf2 *= 2);
79 sum += sqr(c0) * (powerOf2 *= 2);
80 }
while (fabs(c0) > ceiAccuracy);
83 return K * (1 - sum / 2);
86double *KE_cei(
double k,
double *buffer) {
87 double a0, b0, c0, a1, b1, c1, K, sum, powerOf2;
90 buffer =
tmalloc(
sizeof(*buffer) * 2);
93 b0 = sqrt(1 - sqr(k));
103 sum += sqr(c1) * (powerOf2 *= 2);
109 sum += sqr(c0) * (powerOf2 *= 2);
110 }
while (fabs(c0) > ceiAccuracy);
112 buffer[0] = K = PI / (2 * a0);
113 buffer[1] = K * (1 - sum / 2);
132 return (buffer[1] / (1 - k * k) - buffer[0]) / k;
147 return (buffer[1] - buffer[0]) / k;
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
double dK_cei(double k)
Compute the total derivative dK/dk of the complete elliptic integral of the first kind.
double E_cei(double k)
Compute the complete elliptic integral of the second kind, E(k).
double K_cei(double k)
Compute the complete elliptic integral of the first kind, K(k).
double dE_cei(double k)
Compute the total derivative dE/dk of the complete elliptic integral of the second kind.