[Mono-bugs] [Bug 35440][Nor] New - String Evaluation Bug (unsure)
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
11 Dec 2002 12:34:28 -0000
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by bpeyton@ptd.net.
http://bugzilla.ximian.com/show_bug.cgi?id=35440
--- shadow/35440 Wed Dec 11 07:34:28 2002
+++ shadow/35440.tmp.8270 Wed Dec 11 07:34:28 2002
@@ -0,0 +1,325 @@
+Bug#: 35440
+Product: Mono/Class Libraries
+Version: unspecified
+OS: other
+OS Details: Slackware 8
+Status: NEW
+Resolution:
+Severity: Unknown
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: bpeyton@ptd.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: String Evaluation Bug (unsure)
+
+Description of Problem:
+I saw this sometime in the middle of mono0.16 lifetime. I wanted to wait
+till 0.17 because I thought it may have been fixed, but it hasn't. The
+files I have attached are from a program I began awhile ago and have
+completly rewritten since then. The code is pretty awful, I'm sorry.
+
+Steps to reproduce the problem:
+1. compile code to an exe with MS's C# compiler or mcs
+2. run with mono or mint on mono0.17 (or 0.16) with the exe
+3. Type "1 + 1"
+
+Actual Results:
+Get equation string returned 0
+The answer to the equation is 1
+
+
+Expected Results (returns this with MS's .NET runtime on windows):
+Get equation string returned 0
+The answer to the equation is 2
+
+How often does this happen?
+Everytime this program is run
+
+Code:
+##########main.cs######################
+using System;
+using calclib;
+
+namespace console_client
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ class mainclass
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static void Main(string [] args)
+ {
+ string equation;
+ //calclib.calculator calcobj = new calclib.calculator();
+ //Array stack;
+ int count;
+ calclib.parser calcobj = new calclib.parser();
+ //Console.WriteLine("test");
+ equation=Console.ReadLine();
+ Console.WriteLine("Get equation string returned {0}",
+calcobj.getequationstring(equation));
+ Console.WriteLine("The answer to the equation is {0}", calcobj.calculate());
+ Console.ReadLine();
+
+ }
+ }
+}
+######################parser.cs#############################
+using System;
+
+
+namespace calclib
+{
+ /// <summary>
+ /// Summary description for Class1.
+ /// </summary>
+ public class parser
+ {
+ //private System.Collections.Stack numbers = new System.Collections.Stack();
+ //private System.Collections.Stack operators = new
+System.Collections.Stack();
+
+
+ private Double [] numbers= new Double[500];
+ private int numbercount=0;
+ private String [] operators= new String[500];
+ private int operatorcount=0;
+
+ public parser()
+ {
+
+ }
+
+
+
+ public int getequationstring(string equation)
+ {
+ string tempelement="";
+ for (int count=0; count < equation.Length; count++)
+ {
+
+ if (equation[count]!=' ')
+ { //number 48-57
+ tempelement="";
+
+ do
+ {
+ tempelement=tempelement + equation[count];
+ count++;
+ } while (count<equation.Length && equation[count]!=' ' );
+ if (IsNumeric(tempelement))
+ {
+ numbers[numbercount]=Convert.ToDouble(tempelement);
+ numbercount++;
+
+ //numbers.Push(Convert.ToUInt64(tempelement));
+ }
+ else if (tempelement=="pi")
+ {
+ numbers[numbercount]=System.Math.PI;
+ numbercount++;
+
+ }
+ else //will need to be modded for sine and cosine
+ {
+ operators[operatorcount]=tempelement;
+ operatorcount++;
+ }
+
+ }
+ }
+ //printstuff(); //kills all values only for debugging this function
+ return 0;
+ }
+
+ public string calculate()
+ {
+ int currentop=0;
+ int currentnum=0;
+ Double result=0;
+ bool first=true;
+
+ if (operatorcount!=0)
+ {
+
+ for (currentop=0; currentop<=operatorcount; currentop++)
+ {
+
+ switch (operators[currentop])
+ {
+ case "+":
+ {
+ if (first)
+ {
+ result=numbers[currentnum]+numbers[currentnum+1];
+ currentnum+=2;
+ first=false;
+ }
+ else
+ {
+ result=result+numbers[currentnum];
+ currentnum++;
+ }
+
+ break;
+ }
+ case "-":
+ {
+
+ if (first)
+ {
+ result=numbers[currentnum]-numbers[currentnum+1];
+ currentnum+=2;
+ first=false;
+ }
+ else
+ {
+ result=result-numbers[currentnum];
+ currentnum++;
+ }
+
+ break;
+ }
+
+ case "*":
+ {
+
+ if (first)
+ {
+ result=numbers[currentnum]*numbers[currentnum+1];
+ currentnum+=2;
+ first=false;
+ }
+ else
+ {
+ result=result*numbers[currentnum];
+ currentnum++;
+ }
+
+ break;
+ }
+
+ case "/":
+ {
+
+ if (first)
+ {
+ result=numbers[currentnum]/numbers[currentnum+1];
+ currentnum+=2;
+ first=false;
+ }
+ else
+ {
+ result=result/numbers[currentnum];
+ currentnum++;
+ }
+
+ break;
+ }
+ case "^":
+ {
+
+ if (first)
+ {
+ result=System.Math.Pow(numbers[currentnum], numbers[currentnum+1]);
+ currentnum+=2;
+ first=false;
+ }
+ else
+ {
+ result=System.Math.Pow(result,numbers[currentnum]);
+ currentnum++;
+ }
+
+ break;
+ }
+
+ case "sin":
+ {
+
+ if (first)
+ {
+ result=System.Math.Sin(numbers[currentnum]);
+ currentnum++;
+ first=false;
+ }
+ else
+ {
+ result=System.Math.Sin(result);
+
+ }
+
+ break;
+ }
+
+ case "cos":
+ {
+
+ if (first)
+ {
+ result=System.Math.Cos(numbers[currentnum]);
+ currentnum++;
+ first=false;
+ }
+ else
+ {
+ result=System.Math.Cos(result);
+
+ }
+
+ break;
+ }
+
+ case "tan":
+ {
+
+ if (first)
+ {
+ result=System.Math.Tan(numbers[currentnum]);
+ currentnum++;
+ first=false;
+ }
+ else
+ {
+ result=System.Math.Tan(result);
+
+ }
+
+ break;
+ }
+
+
+
+ }
+ }
+
+ }
+ else
+ result=numbers[0];
+ return Convert.ToString(result);
+
+
+ }
+
+ public bool IsNumeric (string x)
+ {
+ try
+ {
+ Double.Parse (x);
+ return true;
+ }
+ catch (FormatException)
+ {
+ return false;
+ }
+ }
+ }
+}