[Mathlib-commitlog] SF.net SVN: mathlib:[831] JMathLib/trunk/src/jmathlib
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-02-04 19:52:37
|
Revision: 831
http://mathlib.svn.sourceforge.net/mathlib/?rev=831&view=rev
Author: st_mueller
Date: 2009-02-04 19:52:35 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
bugfix for a++ and a--
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java
JMathLib/trunk/src/jmathlibtests/core/tokens/testUnaryOperatorToken.java
Modified: JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2009-02-04 18:35:59 UTC (rev 830)
+++ JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2009-02-04 19:52:35 UTC (rev 831)
@@ -859,9 +859,9 @@
/***********************************************************************************/
- /** parse <operand><operator> (e.g. 3! or !(a<3)) */
- /* @param */
- /* @param */
+ /** parse <operand><operator> (e.g. 3! or !(a<3)) */
+ /* @param */
+ /* @param */
/* @return */
private OperandToken parseUnaryOperator(Token nextToken, Stack operandStack)
{
Modified: JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java 2009-02-04 18:35:59 UTC (rev 830)
+++ JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java 2009-02-04 19:52:35 UTC (rev 831)
@@ -47,6 +47,7 @@
case '-':
{
// -- operator
+ // e.g. "a--" first return "a" then decrement by 1
// check if operand is a variable (e.g. a--, bar--)
if(operand instanceof VariableToken)
@@ -62,7 +63,7 @@
//getVariables().getVariable(variable).assign(op);
globals.getVariable(variable).assign(op);
- return op;
+ return result;
}
else if(operand instanceof NumberToken)
{
@@ -77,7 +78,9 @@
case '+':
{
// ++ operator
+ // e.g. "a++" first return "a" then increment by 1
+
// check if operand is a variable (e.g. a++, bar++)
if(operand instanceof VariableToken)
{
@@ -92,7 +95,7 @@
//getVariables().getVariable(variable).assign(op);
globals.getVariable(variable).assign(op);
- return op;
+ return result;
}
else if(operand instanceof NumberToken)
{
Modified: JMathLib/trunk/src/jmathlibtests/core/tokens/testUnaryOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlibtests/core/tokens/testUnaryOperatorToken.java 2009-02-04 18:35:59 UTC (rev 830)
+++ JMathLib/trunk/src/jmathlibtests/core/tokens/testUnaryOperatorToken.java 2009-02-04 19:52:35 UTC (rev 831)
@@ -94,12 +94,15 @@
ml.executeExpression("clear(1)");
ml.executeExpression("a=1");
ml.executeExpression("y=[11,22,33,44,55]");
- ml.executeExpression("y(a++)=77");
+ ml.executeExpression("y(a++)=77"); // "a" will be incremented after indexing
+ // y=[77,22,33,44,55]
ml.executeExpression("b=y(2)");
ml.executeExpression("c=y(a)");
- assertTrue(77.0 == ml.getScalarValueRe("b"));
+ ml.executeExpression("d=y(1)");
+ assertTrue(22.0 == ml.getScalarValueRe("b"));
assertTrue( 2.0 == ml.getScalarValueRe("a"));
- assertTrue(77.0 == ml.getScalarValueRe("c"));
+ assertTrue(22.0 == ml.getScalarValueRe("c"));
+ assertTrue(77.0 == ml.getScalarValueRe("d"));
}
// --
@@ -107,13 +110,16 @@
ml.executeExpression("clear(1)");
ml.executeExpression("a=4");
ml.executeExpression("y=[11,22,33,44,55]");
- ml.executeExpression("y(a--)=88");
+ ml.executeExpression("y(a--)=88"); // decrement will be executed after index operation
+ // y=[11,22,33,88,55]
assertTrue( 3.0 == ml.getScalarValueRe("a"));
ml.executeExpression("b=y(3)");
+ assertTrue(33.0 == ml.getScalarValueRe("b"));
+ ml.executeExpression("b=y(4)");
+ assertTrue(88.0 == ml.getScalarValueRe("b"));
ml.executeExpression("c=y(a--)");
assertTrue( 2.0 == ml.getScalarValueRe("a"));
- assertTrue(88.0 == ml.getScalarValueRe("b"));
- assertTrue(22.0 == ml.getScalarValueRe("c"));
+ assertTrue(33.0 == ml.getScalarValueRe("c"));
}
public void test460() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|