1 package math.linearAlgebra.util; 2 3 public class Maths { 4 5 /** sqrt(a^2 + b^2) without under/overflow. **/ 6 7 public static double hypot(double a, double b) { 8 double r; 9 if (Math.abs(a) > Math.abs(b)) { 10 r = b/a; 11 r = Math.abs(a)*Math.sqrt(1+r*r); 12 } else if (b != 0) { 13 r = a/b; 14 r = Math.abs(b)*Math.sqrt(1+r*r); 15 } else { 16 r = 0.0; 17 } 18 return r; 19 } 20 } 21