summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2016-05-11 19:17:50 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2016-05-21 17:08:13 -0400
commit8fc157a4be20a98dd412dc8ebf2149c97b775711 (patch)
tree94b642928960f550ae3395a0606318bf67f32380
parent4ed368e68d4ba749fc0fe7cb0ef4568350aaa9aa (diff)
downloadopus-8fc157a4be20a98dd412dc8ebf2149c97b775711.tar.gz
Simplifying fast_atan2f()
-rw-r--r--src/analysis.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/analysis.c b/src/analysis.c
index fae0c660..95e79964 100644
--- a/src/analysis.c
+++ b/src/analysis.c
@@ -115,26 +115,20 @@ static const int extra_bands[NB_TOT_BANDS+1] = {
#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);
}
}