summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib/math
diff options
context:
space:
mode:
authorMarcus Müller <marcus@hostalia.de>2018-08-31 23:02:22 +0200
committerMarcus Müller <marcus@hostalia.de>2018-08-31 23:02:22 +0200
commit254fe5e89403d4de1fa6663d09efdf946996aff3 (patch)
tree62877d7ac7fdedf6c397c51e22ac6f97eba97ddf /gnuradio-runtime/lib/math
parent896d1c9da31963ecf5b0d90942c2af51ca998a69 (diff)
parent5ad935c3a3dd46ce2860b13e2b774e4841784616 (diff)
Merge remote-tracking branch 'origin/next' into merge_next
Diffstat (limited to 'gnuradio-runtime/lib/math')
-rw-r--r--[-rwxr-xr-x]gnuradio-runtime/lib/math/gen_sine_table.py6
-rw-r--r--gnuradio-runtime/lib/math/qa_fxpt.cc16
-rw-r--r--gnuradio-runtime/lib/math/qa_fxpt_nco.cc8
-rw-r--r--gnuradio-runtime/lib/math/random.cc8
-rw-r--r--gnuradio-runtime/lib/math/vco.h14
5 files changed, 29 insertions, 23 deletions
diff --git a/gnuradio-runtime/lib/math/gen_sine_table.py b/gnuradio-runtime/lib/math/gen_sine_table.py
index d7d11eff11..5b459fa1a3 100755..100644
--- a/gnuradio-runtime/lib/math/gen_sine_table.py
+++ b/gnuradio-runtime/lib/math/gen_sine_table.py
@@ -20,6 +20,8 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import division
+from __future__ import unicode_literals
import math
import sys
@@ -38,8 +40,8 @@ def gen_approx_table (f, nentries, min_x, max_x):
for i in range (nentries):
a = (i * incx) + min_x
b = ((i + 1) * incx) + min_x
- m = (f(b)-f(a))/(b-a)
- c = (3*a+b)*(f(a)-f(b))/(4*(b-a)) + (f((a+b)/2) + f(a))/2
+ m = (f(b)-f(a)) / (b-a)
+ c = (3*a+b)*(f(a)-f(b))/(4*(b-a)) + (f((a+b)/2) + f(a))//2
abs_error = c+m*a-f(a)
r.append ((m, c, abs_error))
return r
diff --git a/gnuradio-runtime/lib/math/qa_fxpt.cc b/gnuradio-runtime/lib/math/qa_fxpt.cc
index f369cd356a..5073df6e39 100644
--- a/gnuradio-runtime/lib/math/qa_fxpt.cc
+++ b/gnuradio-runtime/lib/math/qa_fxpt.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2004,2013 Free Software Foundation, Inc.
+ * Copyright 2004,2013,2018 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -34,9 +34,9 @@
static const float SIN_COS_TOLERANCE = 1e-5;
BOOST_AUTO_TEST_CASE(t0) {
- BOOST_CHECK(std::abs(M_PI/2 - gr::fxpt::fixed_to_float(0x40000000)) <= SIN_COS_TOLERANCE);
+ BOOST_CHECK(std::abs(GR_M_PI/2 - gr::fxpt::fixed_to_float(0x40000000)) <= SIN_COS_TOLERANCE);
BOOST_CHECK(std::abs(0.0 - gr::fxpt::fixed_to_float(0x00000000)) <= SIN_COS_TOLERANCE);
- BOOST_CHECK(std::abs(-M_PI - gr::fxpt::fixed_to_float(0x80000000)) <= SIN_COS_TOLERANCE);
+ BOOST_CHECK(std::abs(-GR_M_PI - gr::fxpt::fixed_to_float(0x80000000)) <= SIN_COS_TOLERANCE);
if(0) {
/*
@@ -48,9 +48,9 @@ BOOST_AUTO_TEST_CASE(t0) {
* sometimes the answer is off by a few bits at the bottom.
* Hence, the disabled check.
*/
- BOOST_CHECK_EQUAL((int32_t)0x40000000, gr::fxpt::float_to_fixed(M_PI/2));
+ BOOST_CHECK_EQUAL((int32_t)0x40000000, gr::fxpt::float_to_fixed(GR_M_PI/2));
BOOST_CHECK_EQUAL((int32_t)0, gr::fxpt::float_to_fixed(0));
- BOOST_CHECK_EQUAL((int32_t)0x80000000, gr::fxpt::float_to_fixed(-M_PI));
+ BOOST_CHECK_EQUAL((int32_t)0x80000000, gr::fxpt::float_to_fixed(-GR_M_PI));
}
}
@@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(t1) {
BOOST_CHECK(std::abs(-1 - gr::fxpt::sin(-0x40000000)) <= SIN_COS_TOLERANCE);
BOOST_CHECK(std::abs(-0.707106781 - gr::fxpt::sin(-0x20000000)) <= SIN_COS_TOLERANCE);
- for(float p = -M_PI; p < M_PI; p += 2 * M_PI / 3600) {
+ for(float p = -GR_M_PI; p < GR_M_PI; p += 2 * GR_M_PI / 3600) {
float expected = sin(p);
float actual = gr::fxpt::sin(gr::fxpt::float_to_fixed (p));
BOOST_CHECK(std::abs(expected - actual) <= SIN_COS_TOLERANCE);
@@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(t1) {
}
BOOST_AUTO_TEST_CASE(t2) {
- for(float p = -M_PI; p < M_PI; p += 2 * M_PI / 3600) {
+ for(float p = -GR_M_PI; p < GR_M_PI; p += 2 * GR_M_PI / 3600) {
float expected = cos(p);
float actual = gr::fxpt::cos(gr::fxpt::float_to_fixed(p));
BOOST_CHECK(std::abs(expected - actual) <= SIN_COS_TOLERANCE);
@@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(t2) {
}
BOOST_AUTO_TEST_CASE(t3) {
- for(float p = -M_PI; p < M_PI; p += 2 * M_PI / 3600) {
+ for(float p = -GR_M_PI; p < GR_M_PI; p += 2 * GR_M_PI / 3600) {
float expected_sin = sin(p);
float expected_cos = cos(p);
float actual_sin;
diff --git a/gnuradio-runtime/lib/math/qa_fxpt_nco.cc b/gnuradio-runtime/lib/math/qa_fxpt_nco.cc
index cd05747630..da10f49c92 100644
--- a/gnuradio-runtime/lib/math/qa_fxpt_nco.cc
+++ b/gnuradio-runtime/lib/math/qa_fxpt_nco.cc
@@ -50,8 +50,8 @@ BOOST_AUTO_TEST_CASE(t0) {
gr::fxpt_nco new_nco;
double max_error = 0, max_phase_error = 0;
- ref_nco.set_freq((float)(2 * M_PI / SIN_COS_FREQ));
- new_nco.set_freq((float)(2 * M_PI / SIN_COS_FREQ));
+ ref_nco.set_freq((float)(2 * GR_M_PI / SIN_COS_FREQ));
+ new_nco.set_freq((float)(2 * GR_M_PI / SIN_COS_FREQ));
BOOST_CHECK(std::abs(ref_nco.get_freq() - new_nco.get_freq()) <= SIN_COS_TOLERANCE);
@@ -86,8 +86,8 @@ BOOST_AUTO_TEST_CASE(t1) {
gr_complex* new_block = new gr_complex[SIN_COS_BLOCK_SIZE];
double max_error = 0;
- ref_nco.set_freq((float)(2 * M_PI / SIN_COS_FREQ));
- new_nco.set_freq((float)(2 * M_PI / SIN_COS_FREQ));
+ ref_nco.set_freq((float)(2 * GR_M_PI / SIN_COS_FREQ));
+ new_nco.set_freq((float)(2 * GR_M_PI / SIN_COS_FREQ));
BOOST_CHECK(std::abs(ref_nco.get_freq() - new_nco.get_freq()) <= SIN_COS_TOLERANCE);
diff --git a/gnuradio-runtime/lib/math/random.cc b/gnuradio-runtime/lib/math/random.cc
index cedaf4b97f..6a509f1796 100644
--- a/gnuradio-runtime/lib/math/random.cc
+++ b/gnuradio-runtime/lib/math/random.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2002, 2015 Free Software Foundation, Inc.
+ * Copyright 2002,2015,2018 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -39,8 +39,10 @@
#include <config.h>
#endif
-#include <math.h>
#include <gnuradio/random.h>
+#include <gnuradio/math.h>
+
+#include <cmath>
namespace gr {
@@ -155,7 +157,7 @@ namespace gr {
float
random::impulse(float factor = 5)
{
- float z = -M_SQRT2 * logf(ran1());
+ float z = -GR_M_SQRT2 * logf(ran1());
if(fabsf(z) <= factor)
return 0.0;
else
diff --git a/gnuradio-runtime/lib/math/vco.h b/gnuradio-runtime/lib/math/vco.h
index d8a6fbb415..7ac1e1ca6d 100644
--- a/gnuradio-runtime/lib/math/vco.h
+++ b/gnuradio-runtime/lib/math/vco.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2005,2013 Free Software Foundation, Inc.
+ * Copyright 2005,2013,2018 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -25,6 +25,8 @@
#include <gnuradio/sincos.h>
#include <gnuradio/gr_complex.h>
+#include <gnuradio/math.h>
+
#include <vector>
#include <cmath>
@@ -49,13 +51,13 @@ namespace gr {
void adjust_phase(double delta_phase) {
d_phase += delta_phase;
- if(fabs (d_phase) > M_PI){
+ if(fabs (d_phase) > GR_M_PI){
- while(d_phase > M_PI)
- d_phase -= 2*M_PI;
+ while(d_phase > GR_M_PI)
+ d_phase -= 2*GR_M_PI;
- while(d_phase < -M_PI)
- d_phase += 2*M_PI;
+ while(d_phase < -GR_M_PI)
+ d_phase += 2*GR_M_PI;
}
}