complexHypot method
Computes sqrt(x^2 + y^2) without under/overflow.
Uses the magnitude (modulo) of x
and y
.
Implementation
Complex complexHypot(Complex x, Complex y) {
var first = x;
var second = y;
if (y > x) {
first = y;
second = x;
}
if (first == const Complex.zero()) {
return second;
}
final t = second / first;
return first * (const Complex.fromReal(1) + (t * t)).sqrt();
}