[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 05/05: math: updated QA code to test nan an
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 05/05: math: updated QA code to test nan and inf inputs to fast_atan2f. |
Date: |
Tue, 18 Mar 2014 17:51:31 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
trondeau pushed a commit to branch maint
in repository gnuradio.
commit ad49c99483e0561343c541856bc73db8a470d408
Author: Tom Rondeau <address@hidden>
Date: Tue Mar 18 11:32:40 2014 -0400
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.
---
gnuradio-runtime/lib/math/qa_fast_atan2f.cc | 88 ++++++++++++++++++++++++++++-
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 119fb8f..b4f1044 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 80e714c..d72ad67 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_ */