summaryrefslogtreecommitdiff
path: root/gnuradio-core/src
diff options
context:
space:
mode:
authorTom Rondeau2011-10-24 11:34:55 -0400
committerTom Rondeau2011-10-24 11:34:55 -0400
commit645ad4ae1423926f0fb893bbb5d3463b2c17623a (patch)
tree5d5a9665aaa370281e267d0ae6ecd56f552c79ee /gnuradio-core/src
parentc2908fcffe42589a63bcfc63718454965fdec12b (diff)
downloadgnuradio-645ad4ae1423926f0fb893bbb5d3463b2c17623a.tar.gz
gnuradio-645ad4ae1423926f0fb893bbb5d3463b2c17623a.tar.bz2
gnuradio-645ad4ae1423926f0fb893bbb5d3463b2c17623a.zip
core: really fixed this on 32-bit machines (actually tested). Forced to promote to a 64-bit int to handle the overflow, so this is going to take a hit on 32-bit machines.
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r--gnuradio-core/src/lib/general/gri_float_to_int.cc9
-rw-r--r--gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py4
2 files changed, 7 insertions, 6 deletions
diff --git a/gnuradio-core/src/lib/general/gri_float_to_int.cc b/gnuradio-core/src/lib/general/gri_float_to_int.cc
index 8a05da7b4..7f170a9d5 100644
--- a/gnuradio-core/src/lib/general/gri_float_to_int.cc
+++ b/gnuradio-core/src/lib/general/gri_float_to_int.cc
@@ -27,20 +27,21 @@
#define _ISOC9X_SOURCE
#include <gri_float_to_int.h>
#include <math.h>
+#include <stdint.h>
-static const long int MAX_INT = 2147483647; // (2^31)-1
-static const long int MIN_INT = -2147483648; // -2^31
+static const int64_t MAX_INT = 2147483647; // (2^31)-1
+static const int64_t MIN_INT = -2147483647; // -(2^31)-1
void
gri_float_to_int (const float *in, int *out, int nsamples)
{
for (int i = 0; i < nsamples; i++){
- long int r = static_cast<long int>(rint(in[i]));
+ int64_t r = static_cast<int64_t>(rint(in[i]));
if (r < MIN_INT)
r = MIN_INT;
else if (r > MAX_INT)
r = MAX_INT;
- out[i] = r;
+ out[i] = static_cast<int>(r);
}
}
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py
index 2f54d0329..3e0b847a2 100644
--- a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py
@@ -48,8 +48,8 @@ class test_float_to_int (gr_unittest.TestCase):
src_data = ( 2147483647, 2147483648, 2200000000,
-2147483648, -2147483649, -2200000000)
- expected_result = [2147483647, 2147483647, 2147483647,
- -2147483648, -2147483648, -2147483648]
+ expected_result = [ 2147483647, 2147483647, 2147483647,
+ -2147483647, -2147483647, -2147483647]
src = gr.vector_source_f(src_data)
op = gr.float_to_int()
dst = gr.vector_sink_i()