summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib/math
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-runtime/lib/math')
-rw-r--r--gnuradio-runtime/lib/math/fast_atan2f.cc8
-rw-r--r--gnuradio-runtime/lib/math/qa_fast_atan2f.cc51
-rw-r--r--gnuradio-runtime/lib/math/qa_fast_atan2f.h39
3 files changed, 94 insertions, 4 deletions
diff --git a/gnuradio-runtime/lib/math/fast_atan2f.cc b/gnuradio-runtime/lib/math/fast_atan2f.cc
index 3555cf50ec..3c4967d9ab 100644
--- a/gnuradio-runtime/lib/math/fast_atan2f.cc
+++ b/gnuradio-runtime/lib/math/fast_atan2f.cc
@@ -128,13 +128,13 @@ namespace gr {
float alpha, angle, base_angle;
int index;
- /* don't divide by zero! */ // FIXME could get hosed with -0.0
- if((y == 0.0) && (x == 0.0))
- return 0.0;
-
/* normalize to +/- 45 degree range */
y_abs = fabsf(y);
x_abs = fabsf(x);
+ /* don't divide by zero! */
+ if((y_abs < 1.5E-5) && (x_abs < 1.5E-5))
+ return 0.0;
+
//z = (y_abs < x_abs ? y_abs / x_abs : x_abs / y_abs);
if(y_abs < x_abs)
z = y_abs / x_abs;
diff --git a/gnuradio-runtime/lib/math/qa_fast_atan2f.cc b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc
new file mode 100644
index 0000000000..119fb8fe77
--- /dev/null
+++ b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <qa_fast_atan2f.h>
+#include <gnuradio/math.h>
+#include <cppunit/TestAssert.h>
+#include <cmath>
+
+void
+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);
+ }
+ }
+}
+
diff --git a/gnuradio-runtime/lib/math/qa_fast_atan2f.h b/gnuradio-runtime/lib/math/qa_fast_atan2f.h
new file mode 100644
index 0000000000..80e714cd1e
--- /dev/null
+++ b/gnuradio-runtime/lib/math/qa_fast_atan2f.h
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _QA_FAST_ATAN2F_H_
+#define _QA_FAST_ATAN2F_H_
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+
+class qa_fast_atan2f : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE(qa_fast_atan2f);
+ CPPUNIT_TEST(t1);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ void t1();
+};
+
+#endif /* _QA_FAST_ATAN2F_H_ */