double v3;
do if (i == 0) return Math.hypot(v1, v2);
while ((v3 = vector[--i]) == 0);
// Usual magnitude computation, but using double-double arithmetic.
final DoubleDouble sum = new DoubleDouble();
final DoubleDouble dot = new DoubleDouble();
sum.setToProduct(v1, v1);
dot.setToProduct(v2, v2); sum.add(dot);
dot.setToProduct(v3, v3); sum.add(dot);
while (i != 0) {
v1 = vector[--i];
dot.setToProduct(v1, v1);
sum.add(dot);
}
sum.sqrt();
return sum.value;
}