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