Bugs item #1091541, was opened at 2004-12-26 18:03
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=438935&aid=1091541&group_id=44253
Category: Compiler integration
Group: Could cause data loss
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: Mathematical evaluation
Initial Comment:
Entering: (10+(2*3))*(2^(1+2))
into the interaction window gives the faulty result of '16'
when it should be 128. This is quite likely due to the
statement being incorrectly parsed in terms of
parenthesis.
I ran across an identical error writing a calculator
program. In parsing the statement in broke the
statement down recursively and was then attempting to
evaluate (1+2)). This evaluated to 0 instead of three,
causing the entire statement to evaluate incorrectly to
16.
I fixed this in my own program by carefully rewriting the
loop that counted parenthesis as so:
This loop ensured that inner items were processed first.
In doing so it kept a count of how many parenthesis it
had passed, +1 for a left paren, and -1 for a right
paren. Having the imbalance in the expression, that is
one left paren and two right paren's messed up the
count, and the inner expression 1+2 was never
evaluated, but returned '0'.
This bug is visible in the interactions pane, as well as a
System.out.println command in an actual java class.
-jack
JH...@gm...
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=438935&aid=1091541&group_id=44253
|