Skip to content

Commit 2190f7b

Browse files
ayush4874vgvassilev
authored andcommitted
Test: Refactor comp_ellint tests to match atan2/pow style and use numerical API
1 parent 3ff15df commit 2190f7b

File tree

1 file changed

+15
-38
lines changed

1 file changed

+15
-38
lines changed

test/Features/stl-cmath.cpp

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -302,49 +302,21 @@ DEFINE_FUNCTIONS(erf) // x in (-inf,+inf)
302302

303303
//------------------------ Elliptic integrals -----------------------------
304304
//
305-
// Helper wrappers to enable DEFINE_FUNCTIONS for comp_ellint_1
306-
inline float comp_ellint_1f(float x) { return std::comp_ellint_1(x); }
307-
inline long double comp_ellint_1l(long double x) { return std::comp_ellint_1(x); }
308-
309305
// Domain: k in (-1, 1)
310-
DEFINE_FUNCTIONS(comp_ellint_1)
311-
CHECK_ALL_RANGE(comp_ellint_1, -0.9, 0.9);
312-
313-
// Helper wrappers for comp_ellint_2
314-
inline float comp_ellint_2f(float x) { return std::comp_ellint_2(x); }
315-
inline long double comp_ellint_2l(long double x) { return std::comp_ellint_2(x); }
306+
template<typename T> T f_comp_ellint_1(T k) { return std::comp_ellint_1(k); }
307+
float f_comp_ellint_1f(float k) { return std::comp_ellint_1(k); }
308+
long double f_comp_ellint_1l(long double k) { return std::comp_ellint_1(k); }
316309

317310
// Domain: k in (-1, 1)
318-
DEFINE_FUNCTIONS(comp_ellint_2)
319-
CHECK_ALL_RANGE(comp_ellint_2, -0.9, 0.9);
311+
template<typename T> T f_comp_ellint_2(T k) { return std::comp_ellint_2(k); }
312+
float f_comp_ellint_2f(float k) { return std::comp_ellint_2(k); }
313+
long double f_comp_ellint_2l(long double k) { return std::comp_ellint_2(k); }
320314

321-
// comp_ellint_3 takes 2 arguments, so we test it manually (macro doesn't support it)
322-
{
323-
double k = 0.5, nu = 0.3;
324-
double h = 1e-8;
325-
double tol = 1e-5;
315+
// Domain: k in (-1, 1). Fixed nu = 0.5 for testing.
316+
template<typename T> T f_comp_ellint_3(T k) { return std::comp_ellint_3(k, (T)0.5); }
317+
float f_comp_ellint_3f(float k) { return std::comp_ellint_3(k, 0.5f); }
318+
long double f_comp_ellint_3l(long double k) { return std::comp_ellint_3(k, 0.5L); }
326319

327-
// Test differentiation w.r.t 'k' (Arg 0)
328-
auto d_ellint3_k = clad::differentiate(std::comp_ellint_3, 0);
329-
double sym_k = d_ellint3_k.execute(k, nu);
330-
// Numerical approximation: (f(k+h) - f(k-h)) / 2h
331-
double num_k = (std::comp_ellint_3(k + h, nu) - std::comp_ellint_3(k - h, nu)) / (2 * h);
332-
333-
if (std::abs(sym_k - num_k) > tol) {
334-
return 1;
335-
}
336-
337-
// Test differentiation w.r.t 'nu' (Arg 1)
338-
auto d_ellint3_nu = clad::differentiate(std::comp_ellint_3, 1);
339-
double sym_nu = d_ellint3_nu.execute(k, nu);
340-
// Numerical approximation: (f(nu+h) - f(nu-h)) / 2h
341-
double num_nu = (std::comp_ellint_3(k, nu + h) - std::comp_ellint_3(k, nu - h)) / (2 * h);
342-
343-
if (std::abs(sym_nu - num_nu) > tol) {
344-
return 1;
345-
}
346-
}
347-
//
348320

349321
int main() {
350322
// Absolute value
@@ -404,5 +376,10 @@ int main() {
404376
// Error / Gamma functions
405377
CHECK_ALL(erf);
406378

379+
// Elliptic Integrals
380+
CHECK_ALL_RANGE(comp_ellint_1, -0.9, 0.9);
381+
CHECK_ALL_RANGE(comp_ellint_2, -0.9, 0.9);
382+
CHECK_ALL_RANGE(comp_ellint_3, -0.9, 0.9);
383+
407384
return 0;
408385
}

0 commit comments

Comments
 (0)