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-06-02 15:13:35 -0400
commitaeab4cc920a92ab5b9e019de1439f887501348d5 (patch)
treed7a7b54b0b177513f0d647a877af06b3f1cabb17
parent822c26b3e9655019d3d3d18bedd2bc185c8709ad (diff)
downloadopus-aeab4cc920a92ab5b9e019de1439f887501348d5.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);
}
}