changeset 97:7b15f56660fa

implement most of Math module git-svn-id: https://luan-java.googlecode.com/svn/trunk@98 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sat, 09 Mar 2013 07:47:18 +0000
parents 72a4a5550ec7
children 3a0ff21f0c96
files src/luan/lib/MathLib.java
diffstat 1 files changed, 120 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/lib/MathLib.java	Sat Mar 09 03:11:50 2013 +0000
+++ b/src/luan/lib/MathLib.java	Sat Mar 09 07:47:18 2013 +0000
@@ -15,7 +15,30 @@
 		@Override protected void load(LuanState luan) {
 			LuanTable module = new LuanTable();
 			try {
+				add( module, "abs", Double.TYPE );
+				add( module, "acos", Double.TYPE );
+				add( module, "asin", Double.TYPE );
+				add( module, "atan", Double.TYPE );
+				add( module, "atan2", Double.TYPE, Double.TYPE );
+				add( module, "ceil", Double.TYPE );
+				add( module, "cos", Double.TYPE );
+				add( module, "cosh", Double.TYPE );
+				add( module, "deg", Double.TYPE );
+				add( module, "exp", Double.TYPE );
 				add( module, "floor", Double.TYPE );
+				add( module, "log", Double.TYPE );
+				add( module, "min", Double.TYPE, new double[0].getClass() );
+				add( module, "max", Double.TYPE, new double[0].getClass() );
+				add( module, "modf", Double.TYPE );
+				module.put("pi",Math.PI);
+				add( module, "pow", Double.TYPE, Double.TYPE );
+				add( module, "rad", Double.TYPE );
+				add( module, "random" );
+				add( module, "sin", Double.TYPE );
+				add( module, "sinh", Double.TYPE );
+				add( module, "sqrt", Double.TYPE );
+				add( module, "tan", Double.TYPE );
+				add( module, "tanh", Double.TYPE );
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
 			}
@@ -27,8 +50,105 @@
 		t.put( method, new LuanJavaFunction(MathLib.class.getMethod(method,parameterTypes),null) );
 	}
 
+	public static double abs(double x) {
+		return Math.abs(x);
+	}
+
+	public static double acos(double x) {
+		return Math.acos(x);
+	}
+
+	public static double asin(double x) {
+		return Math.asin(x);
+	}
+
+	public static double atan(double x) {
+		return Math.atan(x);
+	}
+
+	public static double atan2(double y,double x) {
+		return Math.atan2(y,x);
+	}
+
+	public static double ceil(double x) {
+		return Math.ceil(x);
+	}
+
+	public static double cos(double x) {
+		return Math.cos(x);
+	}
+
+	public static double cosh(double x) {
+		return Math.cosh(x);
+	}
+
+	public static double deg(double x) {
+		return Math.toDegrees(x);
+	}
+
+	public static double exp(double x) {
+		return Math.exp(x);
+	}
+
 	public static double floor(double x) {
 		return Math.floor(x);
 	}
 
+	public static double log(double x) {
+		return Math.log(x);
+	}
+
+	public static double min(double x,double... a) {
+		for( double d : a ) {
+			if( x > d )
+				x = d;
+		}
+		return x;
+	}
+
+	public static double max(double x,double... a) {
+		for( double d : a ) {
+			if( x < d )
+				x = d;
+		}
+		return x;
+	}
+
+	public static double[] modf(double x) {
+		double i = (int)x;
+		return new double[]{i,x-i};
+	}
+
+	public static double pow(double x,double y) {
+		return Math.pow(x,y);
+	}
+
+	public static double rad(double x) {
+		return Math.toRadians(x);
+	}
+
+	public static double random() {
+		return Math.random();
+	}
+
+	public static double sin(double x) {
+		return Math.sin(x);
+	}
+
+	public static double sinh(double x) {
+		return Math.sinh(x);
+	}
+
+	public static double sqrt(double x) {
+		return Math.sqrt(x);
+	}
+
+	public static double tan(double x) {
+		return Math.tan(x);
+	}
+
+	public static double tanh(double x) {
+		return Math.tanh(x);
+	}
+
 }