atan2 function

double atan2(
  1. double x,
  2. double y
)

calculate atan from x & y

Implementation

double atan2(double x, double y) {
  // Extract the sign bits
  int uxS = _kSignMask & x.round();
  int uyS = _kSignMask & y.round();

  // Determine the quadrant offset
  double q = ((~uxS & uyS) >> 29 | uxS >> 30).toDouble();

  // Calculate the arc tangent in the first quadrant
  double bxyA = abs(_kATanB * x * y);
  double num = bxyA + y * y;
  double atan1Q = num / (x * x + bxyA + num);

// Translate it to the proper quadrant
  int uatan2Q = (uxS ^ uyS) | atan1Q.round();
  return q + uatan2Q.toDouble();
}