Skip to content

Commit

Permalink
Optimize Math.fastAtan2 (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x000006 committed May 14, 2023
1 parent 4b55bac commit 9672295
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/joml/Math.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ else if (v > +1.0)
*/
private static double fastAtan2(double y, double x) {
double ax = x >= 0.0 ? x : -x, ay = y >= 0.0 ? y : -y;
double a = min(ax, ay) / max(ax, ay);
double a = ay > ax ? ax / ay : ay / ax;
double s = a * a;
double r = ((-0.0464964749 * s + 0.15931422) * s - 0.327622764) * s * a + a;
double r = fma(fma(fma(-0.0464964749, s, 0.15931422), s, -0.327622764) * s, a, a);
if (ay > ax)
r = 1.57079637 - r;
r = PI_OVER_2 - r;
if (x < 0.0)
r = 3.14159274 - r;
r = PI - r;
return y >= 0 ? r : -r;
}

Expand Down

0 comments on commit 9672295

Please sign in to comment.