diff options
author | Tom Rondeau <tom@trondeau.com> | 2014-03-18 11:32:40 -0400 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2014-03-18 11:32:40 -0400 |
commit | ad49c99483e0561343c541856bc73db8a470d408 (patch) | |
tree | 947ad8fbc527c42c7a8722854b9f3908eca9731b | |
parent | 5764b7959ab7052b0afd61d887f37fccf4cd6965 (diff) |
math: updated QA code to test nan and inf inputs to fast_atan2f.
When calculating with nan/inf values for x and/or y, make sure they all return and don't segfault. The results of gr_fast_atan2f in these cases may be different than atan2. But since we are concerned about speed with this block over accuracy (especially in these instances), we just want to make sure it doesn't crash.
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fast_atan2f.cc | 88 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fast_atan2f.h | 4 |
2 files changed, 88 insertions, 4 deletions
diff --git a/gnuradio-runtime/lib/math/qa_fast_atan2f.cc b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc index 119fb8fe77..b4f104468e 100644 --- a/gnuradio-runtime/lib/math/qa_fast_atan2f.cc +++ b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc @@ -28,6 +28,7 @@ #include <gnuradio/math.h> #include <cppunit/TestAssert.h> #include <cmath> +#include <limits> void qa_fast_atan2f::t1() @@ -35,17 +36,98 @@ qa_fast_atan2f::t1() static const unsigned int N = 100; float c_atan2; float gr_atan2f; - + for(float i = -N/2; i < N/2; i++) { for(float j =-N/2; i < N/2; i++) { float x = i/10.0; float y = j/10.0; c_atan2 = atan2(x, y); - + gr_atan2f = gr::fast_atan2f(x, y); - + CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0001); } } } +void +qa_fast_atan2f::t2() +{ + float c_atan2; + float gr_atan2f; + float x, y; + + float inf = std::numeric_limits<float>::infinity(); + float nan = std::numeric_limits<float>::quiet_NaN(); + + /* Test x as INF */ + x = inf; + y = 0; + c_atan2 = atan2(x, y); + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0001); + + x = -inf; + y = 0; + c_atan2 = atan2(x, y); + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0001); + + + /* Test y as INF */ + x = 0; + y = inf; + c_atan2 = atan2(x, y); + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0001); + + x = 0; + y = -inf; + c_atan2 = atan2(x, y); + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0001); + + + /* Test x and y as INF */ + x = inf; + y = inf; + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT(isnan(gr_atan2f)); + + + /* Test x as NAN */ + x = nan; + y = 0; + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + + x = -nan; + y = 0; + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + + + /* Test y as NAN */ + x = 0; + y = nan; + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + + x = 0; + y = -nan; + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + + + /* Test mixed NAN and INF */ + x = inf; + y = nan; + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT(isnan(gr_atan2f)); + + x = nan; + y = inf; + gr_atan2f = gr::fast_atan2f(x, y); + CPPUNIT_ASSERT(isnan(gr_atan2f)); +} + diff --git a/gnuradio-runtime/lib/math/qa_fast_atan2f.h b/gnuradio-runtime/lib/math/qa_fast_atan2f.h index 80e714cd1e..d72ad671d7 100644 --- a/gnuradio-runtime/lib/math/qa_fast_atan2f.h +++ b/gnuradio-runtime/lib/math/qa_fast_atan2f.h @@ -30,10 +30,12 @@ class qa_fast_atan2f : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(qa_fast_atan2f); CPPUNIT_TEST(t1); + CPPUNIT_TEST(t2); CPPUNIT_TEST_SUITE_END(); - + private: void t1(); + void t2(); }; #endif /* _QA_FAST_ATAN2F_H_ */ |