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