Thread: [Mathlib-commitlog] SF.net SVN: mathlib:[744] JMathLib/trunk/src/jmathlib/core/tokens
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-01-24 09:15:53
|
Revision: 744
http://mathlib.svn.sourceforge.net/mathlib/?rev=744&view=rev
Author: st_mueller
Date: 2009-01-24 09:15:51 +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/PowerOperatorToken.java
JMathLib/trunk/src/jmathlib/core/tokens/RelationOperatorToken.java
JMathLib/trunk/src/jmathlib/core/tokens/SparseNumberToken.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/PowerOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/PowerOperatorToken.java 2009-01-24 09:13:36 UTC (rev 743)
+++ JMathLib/trunk/src/jmathlib/core/tokens/PowerOperatorToken.java 2009-01-24 09:15:51 UTC (rev 744)
@@ -17,7 +17,7 @@
/**evaluates the operator
@param operands = the operators operands
@return the result as an OperandToken*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
OperandToken result = null;
Modified: JMathLib/trunk/src/jmathlib/core/tokens/RelationOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/RelationOperatorToken.java 2009-01-24 09:13:36 UTC (rev 743)
+++ JMathLib/trunk/src/jmathlib/core/tokens/RelationOperatorToken.java 2009-01-24 09:15:51 UTC (rev 744)
@@ -51,7 +51,7 @@
* @param operands = the operators operands
* @return the result as an OperandToken
*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
ErrorLogger.debugLine("RelationToken: evaluate");
Modified: JMathLib/trunk/src/jmathlib/core/tokens/SparseNumberToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/SparseNumberToken.java 2009-01-24 09:13:36 UTC (rev 743)
+++ JMathLib/trunk/src/jmathlib/core/tokens/SparseNumberToken.java 2009-01-24 09:15:51 UTC (rev 744)
@@ -447,7 +447,7 @@
}
/**Evaluate the token. This causes it to return itself*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
return this;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-01-24 09:17:05
|
Revision: 745
http://mathlib.svn.sourceforge.net/mathlib/?rev=745&view=rev
Author: st_mueller
Date: 2009-01-24 09:16:55 +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/BinaryOperatorToken.java
JMathLib/trunk/src/jmathlib/core/tokens/CaseToken.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/BinaryOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/BinaryOperatorToken.java 2009-01-24 09:15:51 UTC (rev 744)
+++ JMathLib/trunk/src/jmathlib/core/tokens/BinaryOperatorToken.java 2009-01-24 09:16:55 UTC (rev 745)
@@ -1,6 +1,8 @@
package jmathlib.core.tokens;
+import jmathlib.core.interpreter.GlobalValues;
+
/**The base class for all binary operators*/
public class BinaryOperatorToken extends OperatorToken
{
@@ -26,7 +28,7 @@
/**evaluate the operator
@param operands = the operators operands
@return the result as and OperandToken*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
return null;
}
Modified: JMathLib/trunk/src/jmathlib/core/tokens/CaseToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/CaseToken.java 2009-01-24 09:15:51 UTC (rev 744)
+++ JMathLib/trunk/src/jmathlib/core/tokens/CaseToken.java 2009-01-24 09:16:55 UTC (rev 745)
@@ -1,6 +1,7 @@
package jmathlib.core.tokens;
import jmathlib.core.interpreter.ErrorLogger;
+import jmathlib.core.interpreter.GlobalValues;
/**Used to implement if-then-else operations within an expression*/
@@ -31,7 +32,7 @@
/**evaluates the operator
@param operands = the operators operands
@return the result of the test as an OperandToken*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
if(value != null)
{
@@ -39,14 +40,14 @@
((OperandToken)operands[0]),
value);
- OperandToken result = exp.evaluate(null);
+ OperandToken result = exp.evaluate(null, globals);
if(result instanceof LogicalToken)
{
if(((LogicalToken)result).getValue(0))
{
ErrorLogger.debugLine("case is TRUE ");
- code.evaluate(null);
+ code.evaluate(null, globals);
return new LogicalToken(true);
}
}
@@ -54,7 +55,7 @@
else
{
ErrorLogger.debugLine("case is DEFAULT ");
- code.evaluate(null);
+ code.evaluate(null, globals);
return new LogicalToken(true);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-01-24 09:17:40
|
Revision: 746
http://mathlib.svn.sourceforge.net/mathlib/?rev=746&view=rev
Author: st_mueller
Date: 2009-01-24 09:17:31 +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/DelimiterToken.java
JMathLib/trunk/src/jmathlib/core/tokens/FunctionHandleToken.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/DelimiterToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/DelimiterToken.java 2009-01-24 09:16:55 UTC (rev 745)
+++ JMathLib/trunk/src/jmathlib/core/tokens/DelimiterToken.java 2009-01-24 09:17:31 UTC (rev 746)
@@ -1,6 +1,7 @@
package jmathlib.core.tokens;
import jmathlib.core.constants.TokenConstants;
+import jmathlib.core.interpreter.GlobalValues;
/*Class used to represent delimiter tokens such as ( ) and ,*/
public class DelimiterToken extends OperandToken implements TokenConstants
@@ -29,7 +30,7 @@
/**Evaluate the delimiter, just returns the object itself
@param operands = the delimiters operands
@return the delimter token as an OperandToken*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
return this;
}
Modified: JMathLib/trunk/src/jmathlib/core/tokens/FunctionHandleToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/FunctionHandleToken.java 2009-01-24 09:16:55 UTC (rev 745)
+++ JMathLib/trunk/src/jmathlib/core/tokens/FunctionHandleToken.java 2009-01-24 09:17:31 UTC (rev 746)
@@ -1,6 +1,8 @@
package jmathlib.core.tokens;
+import jmathlib.core.interpreter.GlobalValues;
+
/**
*
* @author stefan
@@ -31,7 +33,7 @@
/**Evaluate the token. This causes it to return itself*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
return this;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-01-24 09:22:46
|
Revision: 748
http://mathlib.svn.sourceforge.net/mathlib/?rev=748&view=rev
Author: st_mueller
Date: 2009-01-24 09:22:42 +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/ColonOperatorToken.java
JMathLib/trunk/src/jmathlib/core/tokens/CommandToken.java
JMathLib/trunk/src/jmathlib/core/tokens/ConditionToken.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/ColonOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/ColonOperatorToken.java 2009-01-24 09:20:41 UTC (rev 747)
+++ JMathLib/trunk/src/jmathlib/core/tokens/ColonOperatorToken.java 2009-01-24 09:22:42 UTC (rev 748)
@@ -16,7 +16,7 @@
}
/**evaluates the operator*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
double x1; // minimum
Modified: JMathLib/trunk/src/jmathlib/core/tokens/CommandToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/CommandToken.java 2009-01-24 09:20:41 UTC (rev 747)
+++ JMathLib/trunk/src/jmathlib/core/tokens/CommandToken.java 2009-01-24 09:22:42 UTC (rev 748)
@@ -1,5 +1,7 @@
package jmathlib.core.tokens;
+import jmathlib.core.interpreter.GlobalValues;
+
/**Class for implementing commands */
public class CommandToken extends OperandToken
{
@@ -18,7 +20,7 @@
/**Evaluates the command
@param operands = the commands operands
@return the result of the command as an OperandToken*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
return null;
}
Modified: JMathLib/trunk/src/jmathlib/core/tokens/ConditionToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/ConditionToken.java 2009-01-24 09:20:41 UTC (rev 747)
+++ JMathLib/trunk/src/jmathlib/core/tokens/ConditionToken.java 2009-01-24 09:22:42 UTC (rev 748)
@@ -13,8 +13,9 @@
private OperandToken code;
/**Constructor setting ifRelation and ifCode
- @param _ifRelation = the test relation
- @param _ifCode = the code to execute if the test is true*/
+ * @param _ifRelation = the test relation
+ * @param _ifCode = the code to execute if the test is true
+ */
public ConditionToken(OperandToken _condition, OperandToken _code)
{
condition = _condition;
@@ -40,14 +41,15 @@
}
/**evaluates the operator
- @param operands = the operators operands
- @return the result of the test as an OperandToken*/
- public OperandToken evaluate(Token[] operands)
+ * @param operands = the operators operands
+ * @param
+ * @return the result of the test as an OperandToken*/
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
if(condition != null)
{
ErrorLogger.debugLine("ConditionToken: testing " + condition.toString());
- OperandToken result = condition.evaluate(null);
+ OperandToken result = condition.evaluate(null, globals);
if(result instanceof DoubleNumberToken)
{
@@ -64,7 +66,7 @@
if(tag)
{
// evaluate Code
- code.evaluate(null);
+ code.evaluate(null, globals);
return DoubleNumberToken.one;
}
}
@@ -83,21 +85,20 @@
if (tag)
{
// evaluate Code
- code.evaluate(null);
+ code.evaluate(null, globals);
return DoubleNumberToken.one;
}
}
}
else
{
- code.evaluate(null);
+ code.evaluate(null, globals);
return DoubleNumberToken.one;
}
return null;
}
-
/**Convert the operator to a string
* @return the operator as a string
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <st_...@us...> - 2009-01-25 21:00:26
|
Revision: 775
http://mathlib.svn.sourceforge.net/mathlib/?rev=775&view=rev
Author: st_mueller
Date: 2009-01-25 21:00:19 +0000 (Sun, 25 Jan 2009)
Log Message:
-----------
changed signature of evaluate(Token[] operands)
to
evaluate(Token[] operands, GlobalValues globals)
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/tokens/Expression.java
JMathLib/trunk/src/jmathlib/core/tokens/NumberToken.java
JMathLib/trunk/src/jmathlib/core/tokens/Token.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/Expression.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/Expression.java 2009-01-25 19:29:11 UTC (rev 774)
+++ JMathLib/trunk/src/jmathlib/core/tokens/Expression.java 2009-01-25 21:00:19 UTC (rev 775)
@@ -13,7 +13,7 @@
/**The number of operands*/
private int noChildren = 0;
- /*the operator being held within the node*/
+ /**the operator being held within the node*/
private OperatorToken data;
/**Stores the index of the child being executed*/
@@ -24,14 +24,14 @@
{
super(50);// , "EXPRESSION");
data = null;
- children = null; //new OperandToken[5];
+ children = null;
}
/**Creates an expression with no operands
@param _data = the expressions operator*/
public Expression(OperatorToken _data)
{
- super(50); //, "EXPRESSION");
+ super(50);
data = _data;
children = null;
}
@@ -41,7 +41,7 @@
@param operand = the expressions operand*/
public Expression(OperatorToken _data, OperandToken operand)
{
- super(50); //, "EXPRESSION");
+ super(50);
data = _data;
children = new OperandToken[1];
children[0] = operand;
@@ -54,7 +54,7 @@
@param right = the right hand operand*/
public Expression(OperatorToken _data, OperandToken left, OperandToken right)
{
- super(50); //, "EXPRESSION");
+ super(50);
data = _data;
children = new OperandToken[2];
children[0] = left;
@@ -86,7 +86,7 @@
@param _noChildren = the number of operands*/
public Expression(OperatorToken _data, OperandToken[] _children, int _noChildren)
{
- super(50); //, "EXPRESSION");
+ super(50);
data = _data;
children = _children;
noChildren = _noChildren;
@@ -201,7 +201,7 @@
/**evaluate the data item held within this node
@param ops = the expressions operands
@return the result of the expression as an OperandToken*/
- public OperandToken evaluate(Token[] ops)
+ public OperandToken evaluate(Token[] ops, GlobalValues globals)
{
OperandToken result = null;
ErrorLogger.debugLine("Expression: evaluate " + toString());
@@ -232,7 +232,7 @@
}
// evaluate right-hand argument (e.g. a= 2+3)
- children[1] = right.evaluate(null);
+ children[1] = right.evaluate(null, globals);
//check LEFT side for submatrices (e.g. a(1,:) = [1,2,3] )
if (left instanceof FunctionToken)
@@ -250,7 +250,7 @@
}
}
else if(data instanceof UnaryOperatorToken && (((UnaryOperatorToken)data).getValue() == '+' ||
- ((UnaryOperatorToken)data).getValue() == '-' ) )
+ ((UnaryOperatorToken)data).getValue() == '-' ) )
{
//!!! is this line really necessary !!!!???
//do nothing
@@ -269,11 +269,14 @@
{
if(children[i] != null)
{
+ ErrorLogger.debugLine("Expression: child: "+children[i].toString());
+ //ErrorLogger.debugLine("Expression: globals: "+globals);
+
// check if result should be displayed
dispB = children[i].isDisplayResult();
// evaluate children
- children[i] = children[i].evaluate(null);
+ children[i] = children[i].evaluate(null, globals);
// check if result should be displayed before
if (dispB && children[i]!=null)
@@ -292,14 +295,12 @@
data.setDisplayResult(true);
// evaluate expression
- result = data.evaluate(children);
+ result = data.evaluate(children, globals);
/* set the display state of the result, if the original expression
also has the display state set */
if (isDisplayResult() && (result != null))
- {
result.setDisplayResult(true);
- }
}
else
{
@@ -314,16 +315,16 @@
if (children[i]!=null)
{
ErrorLogger.debugLine("Expression: store ans "+children[i].toString());
- Variable answervar = createVariable("ans");
+ Variable answervar = globals.createVariable("ans");
answervar.assign(children[i]);
}
/* display the result this expression in the user console*/
- if ((children[i] != null) &&
- children[i].isDisplayResult() )
+ if ((children[i] != null) &&
+ children[i].isDisplayResult() )
{
//ErrorLogger.debugLine("Expression: !!!!!!!!! showResult");
- getInterpreter().displayText(" ans = "+ children[i].toString());
+ globals.getInterpreter().displayText(" ans = "+ children[i].toString(globals));
}
}
}
@@ -338,7 +339,7 @@
String result = "";
if (data != null)
{
- result = (data).toString(children);
+ result = data.toString(children);
}
else
{
@@ -352,40 +353,6 @@
return result;
}
-
- /**Performs a multiplication
- @param argument = the value to multiply the expression by
- @return the result as an OperandToken*/
- /*public OperandToken multiply(OperandToken argument)
- {
- return null;
- }
- */
- /**Raise this object to the power of arg
- @param = the value to raise it to the power of
- @return the result as an OperandToken*/
- /*public OperandToken powerOf(OperandToken argument)
- {
- return null;
- }*/
-
- /**add this token to another
- @param arg = the amount to add to it
- @return the result as an OperandToken*/
- /*public OperandToken add(OperandToken argument)
- {
- return null;
- }
- */
-
- /**subtract this token from another
- @param arg = the amount to subtract from it
- @return the result as an OperandToken*/
- /*public OperandToken subtract(OperandToken argument)
- {
- return null;
- }*/
-
/**Builds an expression tree
@param op = the expressions operator
@param left = the left hand operand
Modified: JMathLib/trunk/src/jmathlib/core/tokens/NumberToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/NumberToken.java 2009-01-25 19:29:11 UTC (rev 774)
+++ JMathLib/trunk/src/jmathlib/core/tokens/NumberToken.java 2009-01-25 21:00:19 UTC (rev 775)
@@ -18,7 +18,7 @@
* 2
* 4 */
/**stores the number format for displaying the number*/
- protected static NumberFormat numFormat = NumberFormat.getInstance();
+ protected /*static*/ NumberFormat numFormat = NumberFormat.getInstance();
/**Index for real values within array*/
protected static final int REAL = 0;
@@ -38,6 +38,22 @@
}
/**
+ *
+ * @return
+ */
+ /* protected NumberFormat getNumberFormat()
+ {
+ if (globals==null)
+ ErrorLogger.debugLine("NumberToken: numberFormat: null");
+
+ if (globals!=null)
+ return globals.getNumberFormat();
+ else
+ return NumberFormat.getInstance();
+ }
+ */
+
+ /**
* Convert y,x points to element number n
* @param y
* @param x
@@ -117,6 +133,7 @@
/**Evaluate the token. This causes it to return itself*/
public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
+ ErrorLogger.debugLine("NumberToken: eval");
return this;
}
@@ -148,5 +165,15 @@
return null;
}
+ /**
+ *
+ */
+ public String toString(GlobalValues globals)
+ {
+ ErrorLogger.debugLine("NumberToken: toString(globals)");
+ numFormat = globals.getNumberFormat();
+ return toString();
+ }
+
} // end NumberToken
Modified: JMathLib/trunk/src/jmathlib/core/tokens/Token.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/Token.java 2009-01-25 19:29:11 UTC (rev 774)
+++ JMathLib/trunk/src/jmathlib/core/tokens/Token.java 2009-01-25 21:00:19 UTC (rev 775)
@@ -41,6 +41,16 @@
*/
abstract public String toString();
+ /**
+ *
+ * @param globals
+ * @return
+ */
+ public String toString(GlobalValues globals)
+ {
+ return toString();
+ }
+
/**Converts the token to its MathML representation. At the moment this is unimplemented and just
converts the token into a string*/
public String toMathMlString(OperandToken[] operands)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-01-25 21:01:49
|
Revision: 777
http://mathlib.svn.sourceforge.net/mathlib/?rev=777&view=rev
Author: st_mueller
Date: 2009-01-25 21:01:47 +0000 (Sun, 25 Jan 2009)
Log Message:
-----------
changed signature of evaluate(Token[] operands)
to
evaluate(Token[] operands, GlobalValues globals)
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/tokens/AssignmentOperatorToken.java
JMathLib/trunk/src/jmathlib/core/tokens/numbertokens/DoubleNumberToken.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/AssignmentOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/AssignmentOperatorToken.java 2009-01-25 21:01:09 UTC (rev 776)
+++ JMathLib/trunk/src/jmathlib/core/tokens/AssignmentOperatorToken.java 2009-01-25 21:01:47 UTC (rev 777)
@@ -99,7 +99,7 @@
// clone limits functions/values to preserve for future evalutation
ops[0] = left.getData();
ops[1] = right;
- ops[2] = ((OperandToken)limits[0].clone());
+ ops[2] = (OperandToken)limits[0].clone();
ops[2] = ops[2].evaluate(null, globals);
if (limitsLength==2)
@@ -128,7 +128,7 @@
{
ErrorLogger.debugLine("AssignmentOperatorToken: displayResult");
if ((right!=null))
- globals.getInterpreter().displayText(left.getName() +" = "+ right.toString());
+ globals.getInterpreter().displayText(left.getName() +" = "+ right.toString(globals));
else
globals.getInterpreter().displayText(left.getName() +" = []");
}
Modified: JMathLib/trunk/src/jmathlib/core/tokens/numbertokens/DoubleNumberToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/numbertokens/DoubleNumberToken.java 2009-01-25 21:01:09 UTC (rev 776)
+++ JMathLib/trunk/src/jmathlib/core/tokens/numbertokens/DoubleNumberToken.java 2009-01-25 21:01:47 UTC (rev 777)
@@ -682,7 +682,7 @@
else if (Double.isNaN(re))
result.append("NaN");
else
- //result.append(globals.getNumberFormat().format(re));
+ //result.append(getNumberFormat().format(re));
result.append(numFormat.format(re));
//stefan
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|