changes to build SOR java version
[IRC.git] / Robust / src / ClassLibrary / Math.java
1 public class Math {
2
3   public static double setPI() {
4     double PI = 3.14159265358979323846;
5     return PI;
6   }
7
8   public static double fabs(double x) {
9     if (x < 0) {
10       return -x;
11     } else {
12       return x;
13     }
14   }
15
16   public static double abs(double x) {
17     if (x < 0) {
18       return -x;
19     } else {
20       return x;
21     }
22   }
23
24   public static float abs(float a) {
25     if (a<0)
26       return -a;
27     else return a;
28   }
29
30   public static double max(double a, double b) {
31     if(a == b)
32       return a;
33     if(a > b) {
34       return a;
35     } else {
36       return b;
37     }
38   }
39
40   public static int imax(int a, int b) {
41     if(a == b)
42       return a;
43     if(a > b) {
44       return a;
45     } else {
46       return b;
47     }
48   }
49
50   public static int imin(int a, int b) {
51     if(a == b)
52       return a;
53     if(a > b) {
54       return b;
55     } else {
56       return a;
57     }
58   }
59
60   /** sqrt(a^2 + b^2) without under/overflow. **/
61   public static double hypot(double a, double b) {
62     double r;
63     if (fabs(a) > fabs(b)) {
64       r = b/a;
65       r = fabs(a)*sqrt(1+r*r);
66     } else if (b != 0) {
67       r = a/b;
68       r = fabs(b)*sqrt(1+r*r);
69     } else {
70       r = 0.0;
71     }
72     return r;
73   }
74
75   public static native double sin(double a);
76   public static native double cos(double a);
77   public static native double asin(double a);
78   public static native double acos(double a);
79   public static native double tan(double a);
80   public static native double atan(double a);
81   public static native double exp(double a);
82   public static native double sqrt(double a);
83   public static native double log(double a);
84   public static native double pow(double a, double b);
85
86   public static native float sinf(float a);
87   public static native float cosf(float a);
88   public static native float expf(float a);
89   public static native float sqrtf(float a);
90   public static native float logf(float a);
91   public static native float powf(float a, float b);
92 }