summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib/math/fast_atan2f.cc
diff options
context:
space:
mode:
authorTom Rondeau <tom@trondeau.com>2014-11-25 09:03:50 -0500
committerTom Rondeau <tom@trondeau.com>2014-11-25 09:03:50 -0500
commit114494fabbeb552ebe7b40fb6344418ffac8e736 (patch)
treef1286ba8b820b0bed6cd7708d6c186b19726082d /gnuradio-runtime/lib/math/fast_atan2f.cc
parent95939b21e6a5405674a22a8ea03326accca50652 (diff)
runtime: math: in fast_atan2f, moved nested if that checks for divide by zero out into its own check.
This change mostly affects ARM processors. They seem to not do well with nest branches whereas x86 do fine. Breaking out this nested if makes no computational difference on x86 but makes a ~5-6% improvement for the ARMv7 tests. Also updates the docs to reflect the new mean error from the function.
Diffstat (limited to 'gnuradio-runtime/lib/math/fast_atan2f.cc')
-rw-r--r--gnuradio-runtime/lib/math/fast_atan2f.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/gnuradio-runtime/lib/math/fast_atan2f.cc b/gnuradio-runtime/lib/math/fast_atan2f.cc
index a5ff1cde62..f968310ff8 100644
--- a/gnuradio-runtime/lib/math/fast_atan2f.cc
+++ b/gnuradio-runtime/lib/math/fast_atan2f.cc
@@ -118,7 +118,7 @@ namespace gr {
determine the final angle value in the range of -180 to 180
degrees. Note that this function uses the small angle approximation
for values close to zero. This routine calculates the arc tangent
- with an average error of +/- 0.045 degrees.
+ with an average error of +/- 3.56e-5 degrees (6.21e-7 radians).
*****************************************************************************/
float
@@ -131,11 +131,14 @@ namespace gr {
/* normalize to +/- 45 degree range */
y_abs = fabsf(y);
x_abs = fabsf(x);
+ /* don't divide by zero! */
+ if(!((y_abs > 0.0f) || (x_abs > 0.0f)))
+ return 0.0;
- if (y_abs < x_abs)
- if (x_abs > 0.0) z = y_abs / x_abs; else return 0.0;
+ if(y_abs < x_abs)
+ z = y_abs / x_abs;
else
- if (y_abs > 0.0) z = x_abs / y_abs; else return 0.0;
+ z = x_abs / y_abs;
/* when ratio approaches the table resolution, the angle is */
/* best approximated with the argument itself... */