/* Test for the CORDIC atan2 function Copyright 2019 Ahmet Inan */ #include #include #include #include "unit_circle.hh" #include "cordic.hh" #include "const.hh" template void test() { const int N = 1 << (8*sizeof(TYPE)); for (int n = -N/2; n < N/2; ++n) { TYPE x = nearbyint((N/2-1) * DSP::UnitCircle::cos(n, N)); TYPE y = nearbyint((N/2-1) * DSP::UnitCircle::sin(n, N)); TYPE a = DSP::CORDIC::atan2(y, x); assert(abs(a-n) <= 1); } } int main() { test(); test(); std::cerr << "CORDIC atan2 test passed!" << std::endl; return 0; }