shithub: opus

Download patch

ref: fe4d91c2e3690ec119577537bf1bd696ad673e86
parent: 61714e9edbfc26645358d1b6ca796eb844bc3146
author: Jean-Marc Valin <[email protected]>
date: Wed May 11 15:17:50 EDT 2016

Simplifying fast_atan2f()

--- a/src/analysis.c
+++ b/src/analysis.c
@@ -115,26 +115,20 @@
 #define cE ((float)M_PI/2)
 static OPUS_INLINE float fast_atan2f(float y, float x) {
    float x2, y2;
-   /* Should avoid underflow on the values we'll get */
-   if (ABS16(x)+ABS16(y)<1e-9f)
-   {
-      x*=1e12f;
-      y*=1e12f;
-   }
    x2 = x*x;
    y2 = y*y;
+   /* For very small values, we don't care about the answer, so
+      we can just return 0. */
+   if (x2 + y2 < 1e-18f)
+   {
+      return 0;
+   }
    if(x2<y2){
       float den = (y2 + cB*x2) * (y2 + cC*x2);
-      if (den!=0)
-         return -x*y*(y2 + cA*x2) / den + (y<0 ? -cE : cE);
-      else
-         return (y<0 ? -cE : cE);
+      return -x*y*(y2 + cA*x2) / den + (y<0 ? -cE : cE);
    }else{
       float den = (x2 + cB*y2) * (x2 + cC*y2);
-      if (den!=0)
-         return  x*y*(x2 + cA*y2) / den + (y<0 ? -cE : cE) - (x*y<0 ? -cE : cE);
-      else
-         return (y<0 ? -cE : cE) - (x*y<0 ? -cE : cE);
+      return  x*y*(x2 + cA*y2) / den + (y<0 ? -cE : cE) - (x*y<0 ? -cE : cE);
    }
 }