Example #1
0
 public static void Test()
 {
     string[,] dat = {
         {"abs(0.1^3-0.1^2)","0.009"},
         {"floor(1.9)","1"},
         {"sign(3.3)","1"},
         {" 1.1 + 1.1 * 1.1 ^ -1.1 * 1.1 - 1.1 ","1.08956568403597"},
         {" -1 - 2 + 4 ","1"},
         {" -2 / -4 * 5 ","2.5"},
         {" 1 + 2 * ( 3 + 4 ) ","15"},
         {" sin ( sin ( 0.1 ) ) ","0.0996676641321335"},
         {" sin ( 1 + 2 * ( 3 + cos ( exp ( 1 ) ) ) ) ","-0.894205450594065"},
         {" sqrt ( 1.1E-1 + 1.1E-2 * 1.1E+2 ) ","1.14891252930761"},
         {" log ( -1.1 - exp ( pi * 1.1 ) * 1.1 + 40.1 ) ","1.42303307567651"},
         {" tan ( 1.1 ) - sin ( 1.1 ) / cos ( 1.1 ) ","0"},
     };
     int i, n = dat.GetLength(0);
     string s;
     Translate tr = new Translate();
     for (i = 0; i < n; ++i)
     {
         s = dat[i, 0];
         s = tr.Eval(s);
         if (s != dat[i, 1])
         {
             System.Windows.Forms.MessageBox.Show(dat[i, 0] + " != " + dat[i, 1]);
             return;
         }
     }
     System.Windows.Forms.MessageBox.Show("All OK!");
 }
Example #2
0
 private void button1_Click(object sender, System.EventArgs e)
 {
     string s = textBox1.Text;
     textBox2.Text = "Error";
     listBox1.Items.Clear();
     Translate tr = new Translate();
     tr.Trace += delegate(string before, string after) { listBox1.Items.Add(before); };
     try { s = tr.Eval(s); }
     catch { }
     textBox2.Text = s;
 }