From d39d40c826a1b8e66c4789622c1287d439a26645 Mon Sep 17 00:00:00 2001
From: Marcus Müller <mueller@kit.edu>
Date: Thu, 13 Feb 2020 21:01:56 +0100
Subject: runtime/viterbi: get rid of GR_M_LOG2E constant

Constant was only used to emulate log_2 from ln.

Which is a strange thing to do on a computer with binary floating point
numbers.

Which is a superfluous thing to do when you have ::log2 in C++11.
---
 gnuradio-runtime/include/gnuradio/math.h |  2 +-
 gr-fec/lib/viterbi/metrics.cc            | 15 ++++++---------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/math.h b/gnuradio-runtime/include/gnuradio/math.h
index f628a5875c..e4e2d90315 100644
--- a/gnuradio-runtime/include/gnuradio/math.h
+++ b/gnuradio-runtime/include/gnuradio/math.h
@@ -28,7 +28,7 @@
  * compile. GR_M_PI actually works with C++ but is defined here for the sake
  * of consistency.
  */
-#define GR_M_LOG2E 1.4426950408889634074          /* log_2 e */
+
 #define GR_M_PI 3.14159265358979323846            /* pi */
 #define GR_M_PI_4 0.78539816339744830961566084582 /* pi/4 */
 #define GR_M_TWOPI 6.28318530717958647692         /* 2*pi */
diff --git a/gr-fec/lib/viterbi/metrics.cc b/gr-fec/lib/viterbi/metrics.cc
index c4c9b01af8..a000558276 100644
--- a/gr-fec/lib/viterbi/metrics.cc
+++ b/gr-fec/lib/viterbi/metrics.cc
@@ -35,9 +35,6 @@
 /* Normal function integrated from -Inf to x. Range: 0-1 */
 #define normal(x) (0.5 + 0.5 * erf((x) / GR_M_SQRT2))
 
-/* Logarithm base 2 */
-#define gr_log2(x) (log(x) * GR_M_LOG2E)
-
 namespace gr {
 namespace fec {
 
@@ -69,8 +66,8 @@ void gen_met(int mettab[2][256], /* Metric table, [sent sym][rx symbol] */
 
     /* Prob of this value occurring for a 0-bit */ /* P(s|0) */
     p0 = normal(((0 - OFFSET + 0.5) / amp + 1) / noise);
-    metrics[0][0] = gr_log2(2 * p0 / (p1 + p0)) - bias;
-    metrics[1][0] = gr_log2(2 * p1 / (p1 + p0)) - bias;
+    metrics[0][0] = ::log2(2 * p0 / (p1 + p0)) - bias;
+    metrics[1][0] = ::log2(2 * p1 / (p1 + p0)) - bias;
 
     for (s = 1; s < 255; s++) {
         /* P(s|1), prob of receiving s given 1 transmitted */
@@ -84,8 +81,8 @@ void gen_met(int mettab[2][256], /* Metric table, [sent sym][rx symbol] */
 #ifdef notdef
         printf("P(%d|1) = %lg, P(%d|0) = %lg\n", s, p1, s, p0);
 #endif
-        metrics[0][s] = gr_log2(2 * p0 / (p1 + p0)) - bias;
-        metrics[1][s] = gr_log2(2 * p1 / (p1 + p0)) - bias;
+        metrics[0][s] = ::log2(2 * p0 / (p1 + p0)) - bias;
+        metrics[1][s] = ::log2(2 * p1 / (p1 + p0)) - bias;
     }
     /* 255 is also a special value */
     /* P(s|1) */
@@ -93,8 +90,8 @@ void gen_met(int mettab[2][256], /* Metric table, [sent sym][rx symbol] */
     /* P(s|0) */
     p0 = 1 - normal(((255 - OFFSET - 0.5) / amp + 1) / noise);
 
-    metrics[0][255] = gr_log2(2 * p0 / (p1 + p0)) - bias;
-    metrics[1][255] = gr_log2(2 * p1 / (p1 + p0)) - bias;
+    metrics[0][255] = ::log2(2 * p0 / (p1 + p0)) - bias;
+    metrics[1][255] = ::log2(2 * p1 / (p1 + p0)) - bias;
 #ifdef notdef
     /* The probability of a raw symbol error is the probability
      * that a 1-bit would be received as a sample with value
-- 
cgit v1.2.3