calculateTheta1 function

double calculateTheta1(
  1. double re,
  2. double im
)

Calculate the argument (phase) in radians in the interval (-π, π].

Implementation

double calculateTheta1(double re, double im) {
  // Zero case management, even if math.atan2(0, 0) is 0.0
  if (re == 0 && im == 0) {
    //print("Theta is indeterminate");
    // NaN or 0.0 is acceptable for the complex number zero.
    //We keep 0.0 as the default for compatibility with module 0 calculation.
    return 0.0;
  }
  return math.atan2(im, re);
}