2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: Maths.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.1.1.1 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2003/08/21 21:04:23 $ |
2 |
26 Feb 07 |
jari |
* $Author: braisted $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.util; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
public class Maths { |
2 |
26 Feb 07 |
jari |
/** sqrt(a^2 + b^2) without under/overflow. **/ |
2 |
26 Feb 07 |
jari |
16 |
public static float hypot(float a, float b) { |
2 |
26 Feb 07 |
jari |
17 |
double r; |
2 |
26 Feb 07 |
jari |
18 |
if (Math.abs(a) > Math.abs(b)) { |
2 |
26 Feb 07 |
jari |
19 |
r = b/a; |
2 |
26 Feb 07 |
jari |
20 |
r = (float)(Math.abs(a)*Math.sqrt(1+r*r)); |
2 |
26 Feb 07 |
jari |
21 |
} else if (b != 0) { |
2 |
26 Feb 07 |
jari |
22 |
r = a/b; |
2 |
26 Feb 07 |
jari |
23 |
r = (float)(Math.abs(b)*Math.sqrt(1+r*r)); |
2 |
26 Feb 07 |
jari |
24 |
} else { |
2 |
26 Feb 07 |
jari |
25 |
r = 0.0f; |
2 |
26 Feb 07 |
jari |
26 |
} |
2 |
26 Feb 07 |
jari |
27 |
return(float)r; |
2 |
26 Feb 07 |
jari |
28 |
} |
2 |
26 Feb 07 |
jari |
29 |
} |