switch to spaces only..
[IRC.git] / Robust / src / ClassLibrary / Math.java
1 public class Math {
2   static final double PI=3.14159265358979323846;
3
4   // an alias for setPI()
5   public static double PI() {
6     double PI = 3.14159265358979323846;
7     return PI;
8   }
9
10   public static int abs(int x) {
11     return (x<0)?-x:x;
12   }
13
14   public static long abs(long x) {
15     return (x<0)?-x:x;
16   }
17
18   public static double abs(double x) {
19     return (x<0)?-x:x;
20   }
21
22   public static float abs(float x) {
23     return (x<0)?-x:x;
24   }
25
26   public static double max(double a, double b) {
27     return (a>b)?a:b;
28   }
29
30   public static float max(float a, float b) {
31     return (a>b)?a:b;
32   }
33
34   public static int max(int a, int b) {
35     return (a>b)?a:b;
36   }
37
38   public static long max(long a, long b) {
39     return (a>b)?a:b;
40   }
41
42   public static double min(double a, double b) {
43     return (a<b)?a:b;
44   }
45
46   public static float min(float a, float b) {
47     return (a<b)?a:b;
48   }
49   public static int min(int a, int b) {
50     return (a<b)?a:b;
51   }
52   public static long min(long a, long b) {
53     return (a<b)?a:b;
54   }
55
56   /** sqrt(a^2 + b^2) without under/overflow. **/
57   public static double hypot(double a, double b) {
58     double r;
59     if (abs(a) > abs(b)) {
60       r = b/a;
61       r = abs(a)*sqrt(1+r*r);
62     } else if (b != 0) {
63       r = a/b;
64       r = abs(b)*sqrt(1+r*r);
65     } else {
66       r = 0.0;
67     }
68     return r;
69   }
70
71   public static double rint(double x) {
72     double y = ceil(x);
73     double d = y - x;
74     if( d == 0.5 ) {
75       if( ((int)y)%2 == 0 ) {
76         return y;
77       } else {
78         return y - 1.0;
79       }
80     } else if( d < 0.5 ) {
81       return y;
82     }
83     return y - 1.0;
84   }
85
86   public static native double sin(double a);
87   public static native double cos(double a);
88   public static native double asin(double a);
89   public static native double acos(double a);
90   public static native double tan(double a);
91   public static native double atan(double a);
92   public static native double atan2(double a, double b);
93   public static native double exp(double a);
94   public static native double sqrt(double a);
95   public static native double log(double a);
96   public static native double pow(double a, double b);
97
98   public static native double ceil(double a);
99   public static native double floor(double a);
100
101   public static native float sinf(float a);
102   public static native float cosf(float a);
103   public static native float expf(float a);
104   public static native float sqrtf(float a);
105   public static native float logf(float a);
106   public static native float powf(float a, float b);
107   public static native float ceilf(float a);
108   public static native float IEEEremainder(float f1, float f2);
109 }