[Mathlib-commitlog] SF.net SVN: mathlib:[763] JMathLib/trunk/src/jmathlib/core/tokens
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-01-24 20:18:37
|
Revision: 763
http://mathlib.svn.sourceforge.net/mathlib/?rev=763&view=rev
Author: st_mueller
Date: 2009-01-24 20:18:33 +0000 (Sat, 24 Jan 2009)
Log Message:
-----------
changed signature of evaluate(Token[] operands)
to
evaluate(Token[] operands, GlobalValues globals)
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/tokens/CharToken.java
JMathLib/trunk/src/jmathlib/core/tokens/numbertokens/DoubleNumberToken.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/CharToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/CharToken.java 2009-01-24 19:50:17 UTC (rev 762)
+++ JMathLib/trunk/src/jmathlib/core/tokens/CharToken.java 2009-01-24 20:18:33 UTC (rev 763)
@@ -1,6 +1,7 @@
package jmathlib.core.tokens;
import jmathlib.core.interpreter.*;
+import jmathlib.core.tokens.numbertokens.DoubleNumberToken;
/**Class used to represent any strings used in an expression*/
public class CharToken extends DataToken
@@ -121,6 +122,31 @@
}
/**
+ * cast all char-values into double-array
+ * @return
+ */
+ public double[][] getValuesRe()
+ {
+ // in case char-array is empty return null
+ if ((sizeY==0) && (sizeX==0))
+ return null;
+
+ // create empty return array
+ double[][] d = new double[sizeY][sizeX];
+
+ // convert array of byte to array of double
+ for (int y=0; y<sizeY; y++)
+ {
+ for (int x=0; x<sizeX; x++)
+ {
+ d[y][x]= (double)values[y][x];
+ }
+ }
+
+ return d;
+ }
+
+ /**
* @param
* @param
*/
@@ -161,10 +187,25 @@
if (sizeY!=1)
Errors.throwMathLibException("CharToken: add not supported");
- String answer = new String(values[0]) + arg.toString();
- values[0] = answer.toCharArray();
- sizeX = values[0].length;
- return new CharToken(answer);
+ if (arg instanceof CharToken)
+ {
+ String answer = new String(values[0]) + arg.toString();
+ values[0] = answer.toCharArray();
+ sizeX = values[0].length;
+ return new CharToken(answer);
+
+ }
+ else if (arg instanceof DoubleNumberToken)
+ {
+ double[][] d = getValuesRe();
+
+ DoubleNumberToken num = new DoubleNumberToken(d);
+
+ return arg.add(num);
+ }
+
+ Errors.throwMathLibException("DoubleNumberToken: add: no number");
+ return null;
}
}
Modified: JMathLib/trunk/src/jmathlib/core/tokens/numbertokens/DoubleNumberToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/numbertokens/DoubleNumberToken.java 2009-01-24 19:50:17 UTC (rev 762)
+++ JMathLib/trunk/src/jmathlib/core/tokens/numbertokens/DoubleNumberToken.java 2009-01-24 20:18:33 UTC (rev 763)
@@ -6,9 +6,7 @@
import jmathlib.core.tokens.NumberToken;
import jmathlib.core.tokens.CharToken;
import jmathlib.core.tokens.OperandToken;
-import jmathlib.toolbox.string._double;
-
public class DoubleNumberToken extends NumberToken
{
/**Complex values of the token
@@ -104,8 +102,9 @@
}
/**Constructor taking the numbers value as two double[][]
- @param _real = the numbers value as a 2D array of double
- @param _imaginary = the numbers value as a 2D array of double*/
+ * @param _real = the numbers value as a 2D array of double
+ * @param _imaginary = the numbers value as a 2D array of double
+ */
public DoubleNumberToken(double[][] _real, double[][] _imaginary)
{
super(5, "double");
@@ -142,7 +141,8 @@
}
/**Constructor taking the numbers value as a double[][][]
- @param _values = the numbers value as a 3D array of double*/
+ * @param _values = the numbers value as a 3D array of double
+ */
public DoubleNumberToken(double[][][] _values)
{
super(5, "double");
@@ -253,7 +253,9 @@
/** return a new Number Token of size y*x
- *
+ * @param x
+ * @param y
+ * @return
*/
public DataToken getElementSized(int y, int x)
{
@@ -293,14 +295,15 @@
noElem = sizeY * sizeX;
} // end setSize
- /**@return the real value of the first number*/
+ /**
+ * @return the real value of the first number
+ */
public double getValueRe()
{
return getValueRe(0);
}
/**
- *
* @param y
* @param x
* @return the real value of the number at position y, x
@@ -311,7 +314,6 @@
}
/**
- *
* @param index
* @return
*/
@@ -321,7 +323,6 @@
}
/**
- *
* @param n
* @return
*/
@@ -330,28 +331,36 @@
return values[n][REAL];
}
-
- /**@return the real value of the number at position y, x as an integer*/
+ /**
+ * @param y
+ * @param x
+ * @return the real value of the number at position y, x as an integer
+ */
public int getIntValue(int y, int x)
{
double temp = getValueRe( yx2n(y,x) );
return (new Double(temp)).intValue();
}
- /**@return the imaginary value of the first number*/
+ /**
+ * @return the imaginary value of the first number
+ */
public double getValueIm()
{
return getValueIm(0);
}
- /**@return the imaginary value of the number at position y, x*/
+ /**
+ * @param y
+ * @param x
+ * @return the imaginary value of the number at position y, x
+ */
public double getValueIm(int y, int x)
{
return getValueIm( yx2n(y,x) );
}
/**
- *
* @param index
* @return
*/
@@ -361,7 +370,6 @@
}
/**
- *
* @param n
* @return
*/
@@ -371,7 +379,11 @@
}
- /**@return the absolute value of the number at position y, x*/
+ /**
+ * @param y
+ * @param x
+ * @return the absolute value of the number at position y, x
+ * */
public double getValueAbs(int y, int x)
{
int n = yx2n(y,x);
@@ -379,15 +391,20 @@
return Math.sqrt(temp);
}
- /**@return the angle of the number at position y, x in radians*/
+ /**
+ * @param y
+ * @param x
+ * @return the angle of the number at position y, x in radians
+ */
public double getValueArg(int y, int x)
{
int n = yx2n(y,x);
return Math.atan2(values[n][IMAG], values[n][REAL]);
}
-
- /**@return the real values of the number*/
+ /**
+ * @return the real values of the number
+ */
public double[][] getValuesRe()
{
double[][] temp = new double[sizeY][sizeX];
@@ -406,13 +423,17 @@
return temp;
}
- /**@return the real values of the number*/
+ /**
+ * @return the real values of the number
+ */
public double[][] getReValues()
{
return getValuesRe();
}
- /**@return the imaginary values of the number*/
+ /**
+ * @return the imaginary values of the number
+ */
public double[][] getValuesIm()
{
double[][] temp = new double[sizeY][sizeX];
@@ -433,7 +454,6 @@
/**
- *
* @param n
* @return
*/
@@ -444,7 +464,6 @@
/**
- *
* @param n
* @param num
*/
@@ -453,11 +472,12 @@
values[n][REAL] = ((DoubleNumberToken)num).getValueRe();
values[n][IMAG] = ((DoubleNumberToken)num).getValueIm();
}
-
- /**@return an array of double representing the element at y,x
- @param y = y position in matrix
- @param x = x position in matrix*/
+ /**
+ * @param y = y position in matrix
+ * @param x = x position in matrix
+ * @return an array of double representing the element at y,x
+ */
public double[] getValueComplex(int y, int x)
{
int n = yx2n(y,x);
@@ -465,7 +485,6 @@
}
/**
- *
* @param n
* @return
*/
@@ -475,7 +494,6 @@
}
/**
- *
* @param n
* @param _value
*/
@@ -509,7 +527,6 @@
}
/**
- *
* @param n
* @param _real
* @param _imag
@@ -521,7 +538,6 @@
}
/**
- *
* @param index multidimensional index
* @param _real
* @param _imag
@@ -534,9 +550,10 @@
setValue(n, _real, _imag);
}
-
- /**return the number as a string*/
+ /**return the number as a string
+ * @return
+ */
public String toString()
{
String result = null;
@@ -569,6 +586,11 @@
return result;
}
+ /**
+ * @param dim
+ * @param i
+ * @return
+ */
private String toString(int[] dim, int i)
{
String ret="";
@@ -605,6 +627,10 @@
return ret;
}
+ /**
+ * @param nn
+ * @return
+ */
private String toString2d(int[] nn)
{
StringBuffer buffer = new StringBuffer(20);
@@ -630,7 +656,9 @@
}
/** create string representation of (complex) double values
- @param _values[]={REAL,IMAG} real and imaginary part of number*/
+ * @param _values[]={REAL,IMAG} real and imaginary part of number
+ * @return
+ */
public String toString(double _values[])
{
@@ -654,8 +682,10 @@
else if (Double.isNaN(re))
result.append("NaN");
else
- result.append(getNumberFormat().format(re));
-
+ //result.append(globals.getNumberFormat().format(re));
+ result.append(numFormat.format(re));
+//stefan
+
// imaginary part of number
if((im != 0.0) || Double.isNaN(im))
{
@@ -670,8 +700,10 @@
else if (Double.isNaN(im))
result.append("NaN");
else
- result.append(getNumberFormat().format(im));
-
+ //result.append(getNumberFormat().format(im));
+ result.append(numFormat.format(im));
+ //stefan
+
result.append("i)");
}
return result.toString();
@@ -684,7 +716,9 @@
//}
/**Check if two tokens are equal
- @param arg = the object to check against*/
+ * @param arg = the object to check against
+ * @return
+ */
public boolean equals(Object arg)
{
if(arg instanceof DoubleNumberToken)
@@ -710,7 +744,11 @@
return false;
}
- /**calculate the arg of the complex number at y, x*/
+ /**calculate the arg of the complex number at y, x
+ * @param y
+ * @param x
+ * @return
+ */
public double arg(int y, int x)
{
int n = yx2n(y,x);
@@ -721,8 +759,9 @@
////////////////////////////////////////////////////////////
/**add arg to this object for a number token
- @param = the value to add to it
- @return the result as an OperandToken*/
+ * @param = the value to add to it
+ * @return the result as an OperandToken
+ */
public OperandToken add(OperandToken arg)
{
@@ -798,11 +837,11 @@
else if(arg instanceof CharToken)
{
// 2+'a b'
- CharToken nArg = ((CharToken)arg);
- _double d = new _double();
- DoubleNumberToken numT = (DoubleNumberToken)d.evaluate(new OperandToken[]{nArg});
-
- return this.add(numT);
+ double[][] d = ((CharToken)arg).getValuesRe();
+
+ DoubleNumberToken num = new DoubleNumberToken(d);
+
+ return this.add(num);
}
Errors.throwMathLibException("DoubleNumberToken: add: no number");
@@ -811,8 +850,9 @@
} // and add
/**subtract arg from this object for a number token
- @param = the value to subtract
- @return the result as an OperandToken*/
+ * @param = the value to subtract
+ * @return the result as an OperandToken
+ */
public OperandToken subtract(OperandToken arg)
{
if(!(arg instanceof DoubleNumberToken))
@@ -876,8 +916,9 @@
}
/**Raise this object to the power of arg
- * @param = the value to raise it to the power of
- * @return the result as an OperandToken*/
+ * @param = the value to raise it to the power of
+ * @return the result as an OperandToken
+ */
public OperandToken power(OperandToken arg)
{
// works only on numbers
@@ -1067,8 +1108,9 @@
/**multiply arg by this object for a number token
- @param arg = the value to multiply it by
- @return the result as an OperandToken*/
+ * @param arg = the value to multiply it by
+ * @return the result as an OperandToken
+ */
public OperandToken multiply(OperandToken arg)
{
if(!(arg instanceof DoubleNumberToken))
@@ -1146,9 +1188,10 @@
} // end multiply
/**Multiplies two complex numbers
- @param arg1 = the first complex number as an array of double
- @param arg2 = the second complex number as an array of double
- @return the result as an array of double*/
+ * @param arg1 = the first complex number as an array of double
+ * @param arg2 = the second complex number as an array of double
+ * @return the result as an array of double
+ */
public double[] multiply(double[] arg1, double[]arg2)
{
double[] temp = new double[2];
@@ -1158,8 +1201,9 @@
}
/**divide this object by arg for a number token
- @param arg = the value to divide it by
- @return the result as an OperandToken*/
+ * @param arg = the value to divide it by
+ * @return the result as an OperandToken
+ */
public OperandToken divide(OperandToken arg)
{
if(!(arg instanceof DoubleNumberToken))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|