mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added atan2 test
This commit is contained in:
parent
fe59404f1f
commit
70dc3392fe
1 changed files with 37 additions and 0 deletions
37
tests/atan2_test.cc
Normal file
37
tests/atan2_test.cc
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Test for the atan2 function
|
||||
|
||||
Copyright 2019 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
#include "unit_circle.hh"
|
||||
#include "atan2.hh"
|
||||
#include "const.hh"
|
||||
|
||||
template <typename TYPE, typename PRECISE>
|
||||
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<PRECISE>::cos(n, N);
|
||||
PRECISE y = DSP::UnitCircle<PRECISE>::sin(n, N);
|
||||
PRECISE a = DSP::atan2<TYPE>(y, x);
|
||||
PRECISE b = DSP::Const<PRECISE>::TwoPi() * PRECISE(n) / PRECISE(N);
|
||||
PRECISE e = std::abs(a - b);
|
||||
assert(e < 10 * std::numeric_limits<TYPE>::epsilon());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<float, double>(5000);
|
||||
test<double, long double>(5000);
|
||||
std::cerr << "atan2 function test passed!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue