detSqrt function

double detSqrt(
  1. double x
)

Square root by Newton iteration (deterministic; 0 for x ≤ 0).

Implementation

double detSqrt(double x) {
  if (x <= 0 || x.isNaN) return 0;
  if (x.isInfinite) return x;
  var y = x > 1 ? x : 1.0;
  for (var i = 0; i < 80; i++) {
    final n = 0.5 * (y + x / y);
    if (n == y) break;
    y = n;
  }
  return y;
}