magnitude method

void magnitude (Float64List reals, Float64List imags, bool sqrt)

Applies in-place magnitude or power calculation to the complex- valued array whith the real part reals and the imaginary part imags. according to the following equations: realsi := realsi**2 + imagsi**2 if sqrt is false ("power") realsi := sqrt(realsi**2 + imagsi**2) if sqrt is true ("magnitude")

imags remains unchanged!

Implementation

void magnitude(Float64List reals, Float64List imags, bool sqrt) {
  if (imags == null || (imags.length != reals.length)) {
    throw """real and imaginary spectrum have unequal sizes:
   ${reals.length} + ' / ' + ${imags.length}""";
  }

  double real, imag, realnew;
  int size1 = reals.length - 1;
  for (int i = 0; i <= size1; i++) {
    real = reals[i];
    imag = imags[i];
    realnew = real * real + imag * imag;
    if (sqrt) realnew = math.sqrt(realnew);

    reals[i] = realnew;
  }
}