/* Test for the atan2 function Copyright 2019 Ahmet Inan */ #include #include #include #include #include "unit_circle.hh" #include "atan2.hh" #include "const.hh" template void test(int MAX) { for (int N = 1; N <= MAX; ++N) { for (int n = 1-N/2; n < N/2; ++n) { PRECISE x = DSP::UnitCircle::cos(n, N); PRECISE y = DSP::UnitCircle::sin(n, N); PRECISE a = DSP::atan2(y, x); PRECISE b = DSP::Const::TwoPi() * PRECISE(n) / PRECISE(N); PRECISE e = std::abs(a - b); assert(e < 10 * std::numeric_limits::epsilon()); } } } int main() { test(5000); test(5000); std::cerr << "atan2 function test passed!" << std::endl; return 0; }