support floating point math
authorbdemsky <bdemsky>
Tue, 11 Dec 2007 23:16:59 +0000 (23:16 +0000)
committerbdemsky <bdemsky>
Tue, 11 Dec 2007 23:16:59 +0000 (23:16 +0000)
Robust/src/ClassLibrary/Math.java
Robust/src/Main/Main.java
Robust/src/Runtime/math.c [new file with mode: 0644]
Robust/src/Runtime/runtime.h
Robust/src/buildscript

index 789ccb4f3385fbb4fd78b5138f66f9f3d07041a3..e55c0cf5acbb19ae79917aabe804fece8f5fb7d2 100644 (file)
@@ -1,52 +1,28 @@
 public class Math {
-       //public static final double PI=3.14159265358979323846;
-
-       public double fabs(double x) {
-               if (x < 0) {
-                       return -x;
-               } else {
-                       return x;
-               }
-       }
-
-       public double sin(double rad) {
-               double app;
-               double diff;
-               int inc = 1;
-               double PI=3.14159265358979323846;
-
-               while( rad > 2*PI ) rad -= 2*PI;
-               while( rad < -2*PI ) rad += 2*PI;
-               app = diff = rad;
-               diff = (diff * (-(rad*rad))) / ((2.0 * inc) * (2.0 * inc + 1.0));
-               app = app + diff;
-               inc++;
-               while( fabs(diff) >= 0.00001 ) {
-                       diff = (diff * (-(rad*rad))) / ((2.0 * inc) * (2.0 * inc + 1.0));
-                       app = app + diff;
-                       inc++;
-               }
-               return app;
+    //public static final double PI=3.14159265358979323846;
+    
+    public static double fabs(double x) {
+       if (x < 0) {
+           return -x;
+       } else {
+           return x;
        }
+    }
+    
+    public static float abs(float a) {
+       if (a<0)
+           return -a;
+       else return a;
+    }
 
-       public double cos(double rad) {
-               double app;
-               double diff;
-               int inc = 1;
-               double PI=3.14159265358979323846;
-
-               rad += PI/2.0;
-               while( rad > 2*PI ) rad -= 2*PI;
-               while( rad < -2*PI ) rad += 2*PI;
-               app = diff = rad;
-               diff = (diff * (-(rad*rad))) / ((2.0 * inc) * (2.0 * inc + 1.0));
-               app = app + diff;
-               inc++;
-               while( fabs(diff) >= 0.00001 ) {
-                       diff = (diff * (-(rad*rad))) / ((2.0 * inc) * (2.0 * inc + 1.0));
-                       app = app + diff;
-                       inc++;
-               }
-               return app;
-       }
+    public static native double sin(double a);
+    public static native double cos(double a);
+    public static native double asin(double a);
+    public static native double acos(double a);
+    public static native double tan(double a);
+    public static native double atan(double a);
+    public static native double exp(double a);
+    public static native double sqrt(double a);
+    public static native double log(double a);
+    public static native double pow(double a, double b);
 }
index 706dca58f614559c8e68902e6b7021763d714193..784a95c4aeab2291038850ef46f328717cdbcd6e 100644 (file)
@@ -119,6 +119,7 @@ public class Main {
       readSourceFile(state, ClassLibraryPrefix+"OutputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"File.java");
+      readSourceFile(state, ClassLibraryPrefix+"Math.java");
       readSourceFile(state, ClassLibraryPrefix+"InetAddress.java");
       readSourceFile(state, ClassLibraryPrefix+"SocketInputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"SocketOutputStream.java");
diff --git a/Robust/src/Runtime/math.c b/Robust/src/Runtime/math.c
new file mode 100644 (file)
index 0000000..8baaf3f
--- /dev/null
@@ -0,0 +1,43 @@
+#include "runtime.h"
+#include "math.h"
+#include "structdefs.h"
+
+double CALL11(___Math______cos____D, double ___a___, double ___a___) {
+  return cos(___a___);
+}
+
+double CALL11(___Math______sin____D, double ___a___, double ___a___) {
+  return sin(___a___);
+}
+
+double CALL11(___Math______tan____D, double ___a___, double ___a___) {
+  return tan(___a___);
+}
+
+double CALL11(___Math______acos____D, double ___a___, double ___a___) {
+  return acos(___a___);
+}
+
+double CALL11(___Math______asin____D, double ___a___, double ___a___) {
+  return asin(___a___);
+}
+
+double CALL11(___Math______atan____D, double ___a___, double ___a___) {
+  return atan(___a___);
+}
+
+double CALL11(___Math______log____D, double ___a___, double ___a___) {
+  return log(___a___);
+}
+
+double CALL11(___Math______exp____D, double ___a___, double ___a___) {
+  return exp(___a___);
+}
+
+double CALL11(___Math______sqrt____D, double ___a___, double ___a___) {
+  return sqrt(___a___);
+}
+
+double CALL22(___Math______pow____D_D, double ___a___, double ___b___, double ___a___, double ___b___) {
+  return pow(___a___,___b___);
+}
index fdef2c2ff2facdb131401b35451e78a8d0ee2497..7158c14ff1c9ad960104b00d7a4202541668decf 100644 (file)
@@ -57,6 +57,7 @@ void createstartupobject();
 #define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
 #define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
+#define CALL22(name, rest, rest2, alt1, alt2) name(struct name ## _params * ___params___, rest, rest2)
 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
@@ -67,6 +68,7 @@ void createstartupobject();
 #define CALL02(name, alt1, alt2) name(alt1, alt2)
 #define CALL11(name,rest, alt) name(alt)
 #define CALL12(name,rest, alt1, alt2) name(alt1, alt2)
+#define CALL22(name, rest, rest2, alt1, alt2) name(alt1, alt2)
 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
index fde52d795c08d0099722c9024f987a19950731b9..c2422ae25ca2863e9f204f372c9da95d3537811a 100755 (executable)
@@ -209,6 +209,7 @@ $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
 $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
 $ROBUSTROOT/Runtime/ObjectHash.c \
 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
+$ROBUSTROOT/Runtime/math.c \
 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
 
 if $DSMFLAG