18#include "mdb_thread.h"
20static double ceiAccuracy = 1e-14;
21static MDB_THREAD_LOCK cei_accuracy_lock = MDB_THREAD_LOCK_INITIALIZER;
23static double getCeiAccuracy(
void) {
25 mdb_thread_lock(&cei_accuracy_lock);
26 accuracy = ceiAccuracy;
27 mdb_thread_unlock(&cei_accuracy_lock);
31void setCeiAccuracy(
double newAccuracy) {
32 mdb_thread_lock(&cei_accuracy_lock);
33 ceiAccuracy = newAccuracy;
34 mdb_thread_unlock(&cei_accuracy_lock);
46 double a0, b0, c0, a1, b1;
47 double accuracy = getCeiAccuracy();
50 b0 = sqrt(1 - sqr(k));
60 }
while (fabs(c0) > accuracy);
73 double a0, b0, c0, a1, b1, c1, K, sum, powerOf2;
74 double accuracy = getCeiAccuracy();
77 b0 = sqrt(1 - sqr(k));
87 sum += sqr(c1) * (powerOf2 *= 2);
93 sum += sqr(c0) * (powerOf2 *= 2);
94 }
while (fabs(c0) > accuracy);
97 return K * (1 - sum / 2);
100double *KE_cei(
double k,
double *buffer) {
101 double a0, b0, c0, a1, b1, c1, K, sum, powerOf2;
102 double accuracy = getCeiAccuracy();
105 buffer =
tmalloc(
sizeof(*buffer) * 2);
108 b0 = sqrt(1 - sqr(k));
118 sum += sqr(c1) * (powerOf2 *= 2);
124 sum += sqr(c0) * (powerOf2 *= 2);
125 }
while (fabs(c0) > accuracy);
127 buffer[0] = K = PI / (2 * a0);
128 buffer[1] = K * (1 - sum / 2);
147 return (buffer[1] / (1 - k * k) - buffer[0]) / k;
162 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.